Private Sub GridView1_DataBinding(ByVal sender As ObjectByVal e As System.EventArgs) Handles GridView1.DataBinding
        
'空数据时添加空行
        Dim dt As Object = sender.DataSource
        
If dt.Rows.Count = 0 Then
            dt.Rows.Add(dt.NewRow())
        
End If
    
End Sub


    
Private Sub GridView1_RowDataBound(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        
'隐藏添加的空行
        If e.Row.RowType <> DataControlRowType.Header AndAlso e.Row.RowType <> DataControlRowType.Footer AndAlso e.Row.RowIndex = 0 Then
            
If String.IsNullOrEmpty(sender.DataKeys(e.Row.RowIndex).Value.ToString()) Then
                e.Row.Visible 
= False
            
End If
        
End If

        
'设置网格线式样为边框式样
        For Each tc As TableCell In e.Row.Cells
            tc.ControlStyle.BorderStyle 
= sender.BorderStyle
            tc.ControlStyle.BorderWidth 
= sender.BorderWidth
        
Next
    
End Sub


    
Private Sub GridView1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles GridView1.PreRender
        
'设置网格线颜色为边框颜色
        sender.Attributes("BorderColor"= System.Drawing.ColorTranslator.ToHtml(sender.BorderColor)
    
End Sub
posted on 2008-06-20 12:01  SNS  阅读(1578)  评论(0编辑  收藏  举报