现在的位置: 首页 > 综合 > 正文

关于GridView的一些操作

2013年06月09日 ⁄ 综合 ⁄ 共 1281字 ⁄ 字号 评论关闭
用下面的代码可以改变鼠标滑过时行的背景色
Protected Sub GridView1_RowDataBound(ByVal sender As ObjectByVal 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

下面的代码可以改变GridView中单元格的边框颜色

  Protected Sub GridView2_RowDataBound(ByVal sender As ObjectByVal 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


下面的代码可以添加一个自动编号的列

  Protected Sub GridView1_RowDataBound(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
        
If (e.Row.RowIndex <> -1Then
            
Dim id As Integer = e.Row.RowIndex + 1
            e.Row.Cells(
0).Text = id.ToString & ""
        
End If
         
End Sub

抱歉!评论已关闭.