Solved

StyleSheets in Datagrid Elements

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

Technology Partners: 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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 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