Problem with background color of row in datagrid

  • Thread starter Gabriël van der Kruijk
  • Start date
G

Gabriël van der Kruijk

Hi Folks,

I've been searching the Google groups for a couple of hours now, and the
solution to my problem (setting the color of datagrid rows during runtime):

public class LocalizedDataGrid : System.Web.UI.WebControls.DataGrid
{
protected override void OnInit(EventArgs e)
{
this.ItemCreated+=new
DataGridItemEventHandler(LocalizedDataGrid_ItemCreated);
base.OnInit(e);
}


protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
this.CellPadding = 5;
this.BorderWidth = 0;
base.Render (writer);
}

private void LocalizedDataGrid_ItemCreated(object sender,
DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
e.Item.BackColor = System.Drawing.Color.Red;
}
}

But for some reason my background color of the rows stays white.

Any suggestions?

Greets,
Gab
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top