I have this code in Visual Basic, and it works when I test it. All the rows have alternate colors.
Private Sub GridView1_RowCreated(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim RowNum as Integer
RowNum = e.Row.RowIndex
If RowNum mod 2 = 1 Then
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#DDDDDD'")
Else
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'")
End If
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='DeepSkyBlue'")
e.Row.Attributes("onclick") = Me.Page.ClientScript.GetPostBackClientHyperlink(Me.GridView1, "Select$" & e.Row.RowIndex)
End If
End Sub
Since I am working under C# enviroment, I converted it to C#:
private void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int RowNum = e.Row.RowIndex;
if (RowNum % 2 == 1)
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#DDDDDD'");
}
else
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='DeepSkyBlue'");
e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
}
}
Is that a way I can do same as "Handles" option in Visual Basic? Please provide me the code if possible.