ProtectedSub GridView1_RowDataBound()Sub GridView1_RowDataBound(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound Dim i AsInteger For i =0ToMe.GridView1.Rows.Count Step1 If (e.Row.RowType = DataControlRowType.DataRow) Then e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#99ccff'") e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c") EndIf Next End Sub
下面的代码可以改变GridView中单元格的边框颜色
ProtectedSub GridView2_RowDataBound()Sub GridView2_RowDataBound(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound ForEach tc As TableCell In e.Row.Cells tc.Attributes("style") ="border-color:white" Next End Sub
下面的代码可以添加一个自动编号的列
ProtectedSub GridView1_RowDataBound()Sub GridView1_RowDataBound(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound If (e.Row.RowIndex <>-1) Then Dim id AsInteger= e.Row.RowIndex +1 e.Row.Cells(0).Text = id.ToString &". " EndIf End Sub