Gridview RowCreated is fired before then RowDataBound Event. If we apply any styles to Gridview Controls we have to choose RowDataBound Event.
But the signature of the RowCreated and RowDataBound events has same signature so everyone doing some confusion which event i need to choose.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='red'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='green'");
}
// Not Preferred
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='blue'");
}
// Good Programming
}
Note: If we apply style to apply in RowCreated and RowDataBound evnts. the styles in RowDataBound event is applied why because RowCreated styles are override by RowDataBound event. as well if don't written any style in RowDataBound event then RowCreated Event Style are applicable.
But the signature of the RowCreated and RowDataBound events has same signature so everyone doing some confusion which event i need to choose.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='red'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='green'");
}
// Not Preferred
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='blue'");
}
// Good Programming
}
Note: If we apply style to apply in RowCreated and RowDataBound evnts. the styles in RowDataBound event is applied why because RowCreated styles are override by RowDataBound event. as well if don't written any style in RowDataBound event then RowCreated Event Style are applicable.