Solved

StyleSheets in Datagrid Elements

Posted on 2006-11-14
2
791 Views
Last Modified: 2007-12-19
I want to apply as different style in a datagrid for the header and data elements. How is that done ?
0
Comment
Question by:shelbyinfotech
2 Comments
 
LVL 4

Expert Comment

by:Xeavn
ID: 17939419
Here is a small example of a repeater that I have applied CSS styles to, a datagrid would be similar. The style is actually applied in the <tr> row tag using class="MyCssClass"

<asp:Repeater Id="MySamples"
     RunAt="Server">
<HeaderTemplate>
      <table cellspacing="0" cellpadding="0" frame="box" rules="rows" border="1" style="width:16em;border-collapse:collapse;">
      <tr class="header">
            <th style="padding-right:0;"><asp:CheckBox onclick="sa(this,'MySa');" RunAt="Server" /></th>
            <th style="padding-right:0;"><span>Lab Number</span></th>
            <th style="padding-right:0;"><span>Sample</span></th>
      </tr>
</HeaderTemplate>
<ItemTemplate>
      <tr class="dgitem" onmouseover="l(this,1);" onmouseout="l(this,0);" onclick="chk(this);">
            <td style="padding-right:0;"><asp:CheckBox Id="MyCB" runat="server" /></span></td>
            <td style="padding-right:0.5em;"><span><%# DataBinder.Eval(Container.DataItem, "LabNumber.Value") %></span></td>
            <td style="padding-right:0.5em;"><span><%# DataBinder.Eval(Container.DataItem, "Sample.Name") %></span></td>
      </tr>
</ItemTemplate>
<AlternatingItemTemplate>
      <tr class="dgaltitem" onmouseover="l(this,1);" onmouseout="l(this,0);" onclick="chk(this);">
            <td style="padding-right:0;"><asp:CheckBox Id="MyCB" runat="server" /></span></td>
            <td style="padding-right:0.5em;"><span><%# DataBinder.Eval(Container.DataItem, "LabNumber.Value") %></span></td>
            <td style="padding-right:0.5em;"><span><%# DataBinder.Eval(Container.DataItem, "Sample.Name") %></span></td>
      </tr>
</AlternatingItemTemplate>
<FooterTemplate></table>
</FooterTemplate>
</asp:Repeater>
0
 
LVL 8

Accepted Solution

by:
rodmjay earned 500 total points
ID: 17940080
you can set the cssClass for different elements like this

    <asp:DataGrid runat=server ID=grid>
        <ItemStyle CssClass="something" />
    </asp:DataGrid>

in the css file, you need to get the correct specificity to make this work whick is actually like this

tr.something td
{
    background-color: red;
}
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question