私は C# 環境で作業しており、テストした以下のコードがあり、Visual Basic .Net で動作します。
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
そのため、C# 言語に変換しようとしましたが、動作しませんでした。
C# には「ハンドル」オプションはありません
どういうわけか、"
e.Row.Attributes("onclick")
" は VB では機能しますが、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); } }