Cannot set column width property of Gridview

Ok, this is weird. I've actually seen tonnes of people having this problem... and yet I still haven't been able to find the solution!

Basically, I am trying to set the column width of a particular column on a gridview. No matter what I do, setting word wraps to false, changing the column width of every element I can find it just won't set to a particular size (see code below). I tried doing it in code also in the page_load event (grdOnlineQueries.Columns(3).ItemStyle.Width = 100) and still nothing. Tried changing the headerstyle and autogeneratecolumns = false and anything else I could find... and nothing.

So, some suggestions seem to be that it has something to do with the CSS file. But, I don't think I have a CSS file? Or am I missing something. This is a stylesheet or something right?

Anyway, any ideas?
<asp:BoundField DataField="Date/Time" HeaderText="Date/Time" SortExpression="Date/Time">
                    <ItemStyle Width="100px" Wrap="False" />
                    <ControlStyle Width="100px" />
                    <HeaderStyle Width="100px" Wrap="False" />
                    <FooterStyle Width="100px" Wrap="False" />
                </asp:BoundField>

Open in new window

AidenAAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kdtreshCommented:
Here's a snippet of code from a site I recently built that sets the columns to specific widths. It uses the same itemstyle width you use (without the wrap=false), so I'm not sure there's any difference, but this is working perfectly for me. I'm including the gridview declaration, which also specifies width, maybe that's affecting it?
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="65535"
    AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
    HorizontalAlign="Center" Width="900px" CellPadding="3" ShowFooter="true">
    <Columns>
        <asp:TemplateField HeaderText="#">
            <ItemTemplate>
                <%# Container.DataItemIndex + 1 %>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" Width="15px" />
        </asp:TemplateField>
        <asp:BoundField DataField="firstName" HeaderText="First"
            SortExpression="firstName" >
            <ItemStyle Width="115px" />
        </asp:BoundField>
        <asp:BoundField DataField="lastName" HeaderText="Last" 
            SortExpression="lastName" >
            <ItemStyle Width="150px" />
        </asp:BoundField>
        <asp:BoundField DataField="date" HeaderText="Date" SortExpression="date" 
            DataFormatString="{0:MM/dd/yyyy}">
            <ItemStyle HorizontalAlign="Center" Width="75px" />
        </asp:BoundField>
        <asp:TemplateField HeaderText="Agency" FooterStyle-Font-Bold="true">
            <ItemStyle HorizontalAlign="Center" Width="115px" />
            <ItemTemplate>
                <%# Eval("Agency") %>
            </ItemTemplate>
            <FooterTemplate>
                Total Hours:
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Hrs" FooterStyle-Font-Bold="true">
            <ItemStyle HorizontalAlign="Center" Width="15px" />
            <ItemTemplate>
                <%# GetHours(int.Parse(Eval("Hours").ToString())) %>
            </ItemTemplate>
            <FooterTemplate>
                 <%# GetTotal().ToString() %>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="docket" HeaderText="Docket" />
        <asp:BoundField DataField="notes" HeaderText="Notes" />
    </Columns>
</asp:GridView>

Open in new window

UnifiedISCommented:
If you are using a CSS (cascading style sheet), you would have a line in the <head> like this:
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />

Your gridview control would also need to reference a section of the CSS in the CssClass property.
AidenAAuthor Commented:
Hi, well I figured out the problem. Basically what happens is that if the gridview table is small... within the size of the sheet, then you can resize the columns. If there are so many columns that it is wider than the size of the sheet then you don't seem to be able to resize the columns (at least I can't anyway).

So... I'm just seeing if there is some way round this, maybe with using css or something. But I don't really know much about this so just looking at it now
AidenAAuthor Commented:
The problem appears to be that the table width was set to 100%. As it was a large table, changing this to 6000px means that any column widths I change are now reflected correctly onto the Gridlayout

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.