GridView 控件没有提供属性设定内框线的颜色,不过我们可以设定 GridView 的 Attributes("bordercolor") 来达到这个需求。
以下的范例就是将 GridView 的内框线设为蓝色。
1: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
2: GridView1.Attributes("bordercolor") = System.Drawing.ColorTranslator.ToHtml(Drawing.Color.Blue)
3: End Sub
1: Imports System
2: Imports System.Collections.Generic
3: Imports System.ComponentModel
4: Imports System.Text
5: Imports System.Web
6: Imports System.Web.UI
7: Imports System.Web.UI.WebControls
8: Imports System.Drawing
9:
10: < _
11: Description("GridView 控件"), _
12: ToolboxData("<{0}:TBGridView runat=server></{0}:TBGridView>") _
13: > _
14: Public Class TBGridView
15: Inherits GridView
16: Private FGridLineColor As Color
17:
18: ''' <summary>
19: ''' GridView 网格线颜色。
20: ''' </summary>
21: < _
22: Description("GridView 网格线颜色"), _
23: TypeConverter(GetType(WebColorConverter)), _
24: Category("Appearance"), _
25: DefaultValue(GetType(Color), "")> _
26: Public Property GridLineColor() As Color
27: Get
28: Return FGridLineColor
29: End Get
30: Set(ByVal value As Color)
31: FGridLineColor = value
32: End Set
33: End Property
34:
35: ''' <summary>
36: ''' 输出客户端检视的 HTML 码。
37: ''' </summary>
38: ''' <param name="writer">用来在客户端浏览器上呈现服务器控件内容。</param>
39: Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
40: If Me.GridLineColor <> Drawing.Color.Empty Then
41: Me.Attributes("bordercolor") = System.Drawing.ColorTranslator.ToHtml(Me.GridLineColor)
42: End If
43: MyBase.Render(writer)
44: End Sub
45: End Class