Hi,
I want to change the cell color in gridview in my asp.net project. but i don't know how to change the color in runtime.
If you have any idea about this please help me.
Printable View
Hi,
I want to change the cell color in gridview in my asp.net project. but i don't know how to change the color in runtime.
If you have any idea about this please help me.
In RowDataBound event of GridView, you can do that.
use this code,
Same can do with datagrid in Item databound event.Code:protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Gray;
}
}
Hope this helps you.
You can use a template or you can handle the rowdatabound event. if you handle the event, you can simply change the background of the cell with code similar to this one:
void Handle( object sender, GriViewRowEventArgs args )
{
args.Row.Cells[put the position of the cell here].BackColor = your color here;
}
You can refer to http://msdn.microsoft.com/en-us/library/aa479342.aspx for more information about gridview control.
If you want to change the color of selected row or cell then,
try the below one...
Code:Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
GridView1.SelectedRow.Cells(4).BackColor = Drawing.Color.Red
End Sub
Useful Materials. They works for me. Thanks a lot :)