tags:

views:

509

answers:

2

I have a GridView control (which renders to table, tr, td) with some BoundFields and TemplateFields. Essentially, I am displaying two columns, Application Name and Notes (as a TextBox), and I want 35%, 65% relative widths. Here is my asp.net markup:

<asp:GridView ID="gridRequestedApps" DataSourceID="llbRequestedApplications" runat="server" 
    AutoGenerateColumns="False" 
    DataKeyNames="ComputerID, RequestID"  
    EnableViewState="False" 
    cssclass="xGridview">
    <Columns>
        <asp:BoundField DataField="ComputerID" HeaderText="ID" SortExpression="ComputerID" Visible="False" />
        <asp:BoundField DataField="RequestID" HeaderText="ID" SortExpression="RequestID" Visible="False" />
        <asp:TemplateField HeaderText="Application Name" ItemStyle-Width="35%" ItemStyle-Wrap="false">
            <ItemTemplate><asp:TextBox ID="ApplicationName" runat="server" Text='<%# Bind("ApplicationName") %>' CssClass="input_text"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Notes" ItemStyle-Width="65%">
            <ItemTemplate>
            <div style="width:100%; overflow:hidden">
            <asp:TextBox ID="UserNotes" runat="server" Text='<%# Bind("UserNotes") %>' CssClass="input_text" style="overflow:hidden"></asp:TextBox>
            </div>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Now at one point (with slightly different html than shown above), I did have the 35/65 relative widths working. However, I then noticed that if I put long text into the textbox, it was growing horizontally stretching its containing table past 100% width. (This is in IE7....in Firefox, the overflow:hidden seemed to be working).

So, I started messing with the CSS to try to fix the bug in IE, but now, not only does it still overflow, but my column widths are no longer respecting the 36/65 settings.

+2  A: 

Before jQuery, try this first. I found it by googling "ie overflow:hidden table cell".

How to prevent HTML tables from becoming too wide

Using Javascript for styles usually isn't a good idea, especially if later on in the product's life another developer comes along and wants to, say, add a column. Agreed, sometimes hacking a solution together feels nicer in the short term, but it can only lead to headaches in the future.

Matchu
Many thanks for the link... table-layout:fixed certainly seems to have done something...so now it seems a large portion of the textbox itself is hidden, rather than having the contained text itself hidden (as is the behaviour when initially entering)...so it looks like this might be the proper first step on the journey to getting this right. I'd still like to investigate the brute force way as it seems more failsafe, albeit not recommended. :)
tbone
So it seems this fixed the overflow problem, but the column width is still no longer working. God I love CSS!
tbone
Is this page live anywhere where I could mess with it? Even a snapshot of the HTML rather than the live site would be fine.
Matchu
Unfortunately no. I think part of the problem is ASP stupidity layered on top of CSS stupidity. I think I've figured out the width issue, one must use HeaderStyle-Width="25%". ItemStyle-Width is (seemingly) ignored.
tbone
Question about table-layout...is this a fairly obscure CSS setting? I've never used it before. Does one only learn these things in the school of hard knocks? Articles like this: http://sweatte.wordpress.com/css-tips/ sure makes one feel thats the way...hence my desire to try to brute force things.
tbone
Since people don't really use tables in a layout-depends-on-it way anymore, table-layout doesn't come up much. But yeah, Google is your friend when it comes to any CSS issues - it's fairly likely someone else has seen it before.
Matchu
A: 

Hi, just solved myself this problem, and I fell just...

Change document type definition to

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

but care that other parts of the page don't start jumping around.

Nikola