Set column size with additional style sheet setting

M

Matt

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top