【发布时间】:2016-05-05 19:56:45
【问题描述】:
我有一个 GridView,在它的 RowDataBound 事件中,我试图将列的格式设置为“dd MMM yyyy”。我首先检查RowType是否为DataRow,我的代码如下所示:
If e.Row.RowType = System.Web.UI.WebControls.DataControlRowType.DataRow Then
Dim ColCount As Integer
ColCount = e.Row.Cells.Count
For looper = 0 To ColCount - 1
Dim cell As TableCell = e.Row.Cells(looper)
' For now I have hardcoded the Table Name
Dim TempTabName As String = "STAFF"
Dim TempColName As String
Dim TempColType As String
Dim CurrCol As BoundField = DirectCast(DirectCast(e.Row.Cells(looper), DataControlFieldCell).ContainingField, BoundField)
' Extracting Column Name
TempColName = CurrCol.HeaderText
' Extracting Column Type (varchar, datetime etc)
TempColType = GetColType(TempTabName, TempColName)
' Depending on Column Type Set Format
' Depending on Column Type Set Format
Select Case TempColType
Case "varchar"
status.Text = "We are at varchar"
Case "nvarchar"
status.Text = "We are at nvarchar"
Case "char"
status.Text = "We are at char"
Case "datetime"
status.Text = "We are at datetime"
CurrCol.DataFormatString = "{0:dd/MM/yy}"
Case "date"
status.Text = "We are at date"
Case "time"
status.Text = "We are at time"
Case "float"
status.Text = "We are at float"
End Select
Next
End If
当我在 CurrCol.DataFormatString 行上运行此代码时,我收到错误“System.Web.dll 中发生'System.NotSupportedException' 类型的异常,但未在用户代码中处理”。附加信息:不支持指定的方法
谁能告诉我我做错了什么?或者有人可以用一些示例代码来解释如何实现同样的效果吗?
【问题讨论】: