Private Sub GridView1_DataBinding(ByVal sender As Object, ByVal 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 Object, ByVal 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 Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
'设置网格线颜色为边框颜色
sender.Attributes("BorderColor") = System.Drawing.ColorTranslator.ToHtml(sender.BorderColor)
End Sub
'空数据时添加空行
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 Object, ByVal 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 Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
'设置网格线颜色为边框颜色
sender.Attributes("BorderColor") = System.Drawing.ColorTranslator.ToHtml(sender.BorderColor)
End Sub