Solved

StyleSheets in Datagrid Elements

Posted on 2006-11-14
2
807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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