Solved

StyleSheets in Datagrid Elements

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now