Is it possible to give individual cells in a data grid view row different styles such as backcolor, fontcolor etc?
I do not mean giving the whole row a new style, only a specific cell.
Is it possible to give individual cells in a data grid view row different styles such as backcolor, fontcolor etc?
I do not mean giving the whole row a new style, only a specific cell.
Something like this?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string imageName = e.Row.Cells[0].Text.ToString();
e.Row.Cells[1].Attributes.Add(“Style”,
“background-image: url(’images/” + imageName + “‘);”);
}
}
In VB example. The key is to access the RowDataBound event and use the e.Row.Cells(number).Attributes.Add function.
Example below shows how you could add a mouse over event to effect the cell.
Protected Sub gridview1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridview1.RowDataBound
' If it got past the header
If e.Row.RowType = DataControlRowType.DataRow Then
' When mouse over occurs
e.Row.Cells(1).Attributes.Add("onMouseOver", "this.style.fontWeight='Bold'")
End If
End Sub
certainly:
Me.myDatagridview.Rows(0).Cells(0).Style.ForeColor = Color.Aqua