Solved

StyleSheets in Datagrid Elements

Posted on 2006-11-14
2
811 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

632 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