Set column size with additional style sheet setting

Discussion in 'ASP .Net Datagrid Control' started by Matt, Jul 1, 2003.

  1. Matt

    Matt Guest

    My goal is to use my styles.css to set the width of certain columns in
    my datagrid. My hope is to use the style sheet to alter the column size
    instead of having to change it in my HTML.

    I can use custom styles set the general look of the DataGrid without any
    problem. For example, here's some of my code that works now:

    <asp:DataGrid id="DataGrid1" runat="server" ....
    <SelectedItemStyle
    CssClass="DataGrid_SelectedItemStyle"></SelectedItemStyle>
    <ItemStyle CssClass="DataGrid_ItemStyle"></ItemStyle>
    <HeaderStyle CssClass="DataGrid_HeaderStyle"></HeaderStyle>
    <FooterStyle CssClass="DataGrid_FooterStyle"></FooterStyle>
    <Columns> ...

    Using this information my grid has the custom look I want controlled by
    the style sheet. But, I want to shrink some of the columns because they
    are too big by default (mostly because my footer has textboxes in it.
    The only way I found to do this is the following:

    <asp:TemplateColumn HeaderText="FTE">
    <ItemTemplate>
    <asp:Label id="lblFTE" Width="40px" runat="server" Text='<%#
    DataBinder.Eval(Container.DataItem, "fte") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:textbox id="txtFTE_Add" Width="40px" Text=""
    Runat="server"></asp:textbox>
    </FooterTemplate>
    <EditItemTemplate>
    <asp:TextBox id="txtFTE_Edit" Width="40px" runat="server"
    Text='<%# DataBinder.Eval(Container.DataItem, "fte") %>'></asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>


    I had to specify Width="40px" for each template of the column. I do this
    for at least 5 other columns. If I decide to go to 45px I need to make
    something like 18 changes.

    I tried to use the CssClass= parm inside the template definitions but it
    was pretty much ignored. Perhaps I just got my syntax wrong. My other
    concern was that maybe I wasn't allowed to set the style because I had
    already set it at the DataGrid level.

    If anyone has done this and can include the styles.css and aspx code I'd
    appreciate it.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Matt, Jul 1, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. moondaddy
    Replies:
    4
    Views:
    497
    Steven Cheng[MSFT]
    Apr 29, 2004
  2. Juno
    Replies:
    1
    Views:
    543
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Aug 7, 2004
  3. Replies:
    0
    Views:
    806
  4. Replies:
    0
    Views:
    549
  5. Replies:
    4
    Views:
    134
    Ian Collins
    Jul 14, 2006
Loading...

Share This Page