在 asp.net 可编辑的 gridview 中,我的标题文本为“FieldName *”。因为我允许用户输入数据并且数据是强制性的。
我可以在标题中将 FieldName 设置为蓝色,将 * 设置为红色吗?如果是的话..怎么样?
您可以将 HTML 代码插入HeaderText
到FieldName
.
像这样
HeaderText="<font color="blue">FieldName </font><font color="red">*</font>"
该页面将解释 HTML 代码并按照您的需要显示它。但是您可能必须HtmlEncode
为您设置属性BoundField
以强制页面解释 HTML 代码。
你可以用这段代码做点什么。
Protected Sub gvName_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvIndexing.RowCreated
If e.Row.RowType = DataControlRowType.Header Then
Dim oGridView As GridView = CType(sender, GridView)
Dim oGridViewRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
Dim oTableCell As TableCell = New TableCell()
oTableCell.Text = "Header Value"
oTableCell.CssClass = "GridViewHeaderCSSClass"
oTableCell.ColumnSpan = 2
oGridViewRow.Cells.Add(oTableCell)
oGridView.Controls(0).Controls.AddAt(0, oGridViewRow)
Else
Dim oGridView As GridView = CType(sender, GridView)
oGridView.ShowHeader = False
End If
End Sub