Set style or width at column level of datagrid

Discussion in 'ASP .Net Datagrid Control' started by Matt, Jun 30, 2003.

  1. Matt

    Matt Guest

    I have a datagrid that is using some custom styles very nicely by
    using the following code:

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

    The problem is that I want to set the width of SOME columns with a
    style sheet setting. The only way I found to control the width was to
    hard code it in the column definition. Here's a template column that
    works:

    <asp:TemplateColumn HeaderText="FTE">
    <HeaderStyle Width="10px"></HeaderStyle>
    <ItemStyle Width="10px"></ItemStyle>
    <FooterStyle Width="10px"></FooterStyle>
    <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 tried using the cssclass="abc" parm inside each template declaration
    but that had zero effect.

    I want someway to set the individual column width using Styles.css so
    I can change it quickly for several columns at once. Any ideas?
    Matt, Jun 30, 2003
    #1
    1. Advertising

  2. Matt

    Tim Guest

    Good Luck, I've tried exactly what your trying, with no effect. I got
    ASP.net Web Matrix to see if it was in there. But I guess there isn't
    anything you can do? My resort was placing blank images that were 1px high
    and the width I wanted the columns to be, thus making it wider.

    Lemme know if that idea works for you.

    Tim

    "Matt" <> wrote in message
    news:...
    > I have a datagrid that is using some custom styles very nicely by
    > using the following code:
    >
    > <asp:DataGrid id="DataGrid1" runat="server" Width="828px"
    > ShowFooter="True" >
    > <SelectedItemStyle

    CssClass="DataGrid_SelectedItemStyle"></SelectedItemStyle>
    > <ItemStyle CssClass="DataGrid_ItemStyle"></ItemStyle>
    > <HeaderStyle CssClass="DataGrid_HeaderStyle"></HeaderStyle>
    > <FooterStyle CssClass="DataGrid_FooterStyle"></FooterStyle>
    > <Columns> ...
    >
    > The problem is that I want to set the width of SOME columns with a
    > style sheet setting. The only way I found to control the width was to
    > hard code it in the column definition. Here's a template column that
    > works:
    >
    > <asp:TemplateColumn HeaderText="FTE">
    > <HeaderStyle Width="10px"></HeaderStyle>
    > <ItemStyle Width="10px"></ItemStyle>
    > <FooterStyle Width="10px"></FooterStyle>
    > <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 tried using the cssclass="abc" parm inside each template declaration
    > but that had zero effect.
    >
    > I want someway to set the individual column width using Styles.css so
    > I can change it quickly for several columns at once. Any ideas?
    Tim, Jul 1, 2003
    #2
    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. AndrewF
    Replies:
    1
    Views:
    741
    Bruce Barker
    Oct 10, 2005
  2. Charleees
    Replies:
    2
    Views:
    8,186
    Eliyahu Goldin
    Jun 20, 2006
  3. Cal
    Replies:
    1
    Views:
    521
    Tim B
    Jan 8, 2007
  4. pabbu
    Replies:
    8
    Views:
    708
    Marc Boyer
    Nov 7, 2005
  5. Carl Howarth

    DG Column Width vs Table Column Width

    Carl Howarth, Oct 22, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    253
    Eliyahu Goldin
    Oct 24, 2004
Loading...

Share This Page