关于GridView的一些操作
用下面的代码可以改变鼠标滑过时行的背景色
下面的代码可以改变GridView中单元格的边框颜色
下面的代码可以添加一个自动编号的列
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim i As Integer
For i = 0 To Me.GridView1.Rows.Count Step 1
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")
End If
Next
End Sub
Dim i As Integer
For i = 0 To Me.GridView1.Rows.Count Step 1
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")
End If
Next
End Sub
下面的代码可以改变GridView中单元格的边框颜色
Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
For Each tc As TableCell In e.Row.Cells
tc.Attributes("style") = "border-color:white"
Next
End Sub
For Each tc As TableCell In e.Row.Cells
tc.Attributes("style") = "border-color:white"
Next
End Sub
下面的代码可以添加一个自动编号的列
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
If (e.Row.RowIndex <> -1) Then
Dim id As Integer = e.Row.RowIndex + 1
e.Row.Cells(0).Text = id.ToString & ". "
End If
End Sub
If (e.Row.RowIndex <> -1) Then
Dim id As Integer = e.Row.RowIndex + 1
e.Row.Cells(0).Text = id.ToString & ". "
End If
End Sub