how to customize row in a datagrid

M

Mukesh

Hi

I am creating an application in which i have to show each row of
datagrid in a specific color according to the value stored in
database.short of email inbox type application where each row shown in a
specific color showing weather the mail is read or unread.
I am using asp.net 1.1 , visual studio 2003.

Plz help

Mukesh
 
C

Chineme Nnamdi

For the purpose of this explanation I'm assuming that you have a datagrid on a page called DataGrid1 and the dataitem bound to each row of the datagrid is of type "MyObject". You can attach the method below to the ItemDataBound event of the datagrid.

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
MyObject obj = e.Item.DataItem as MyObject;
e.Item.CssClass = obj.IsActive ? "style1" : "style2";

//or

//e.Item.BackColor = obj.IsActive ? Color.Beige : Color.WhiteSmoke;
}


Hope that helps.

Chineme Nnamdi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top