blah blah blah is here! blah blah » Close

up1down
link

Guys, how do i change the text forecolor on the status in the datagrid cell? I have this working fine on a windows form app, but in the world of asp.net this is slightly different to me. I'm assuming i use the code in the Default.aspx.cs file?

I have the grid populating ok, but now i want to format the text colour if column "User" has a value of "Mike" in the cell, My datagrid is called: GridView1

last answered one year ago

1 answers

link

ASP.NET isn't my forte either but, assuming (from the name) it's a GridView rather than the old DataGrid control, I think you'll need to handle its RowDataBound event. Something like this:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// suppose User column has an index of 1
if (e.Row.Cells[1].Text == "Mike") e.Row.Cells[1].ForeColor = System.Drawing.Color.Red; // or whatever
}

Thanks vulpes, I did get it working on the above advice.

Feedback