【发布时间】:2013-12-06 08:50:50
【问题描述】:
我想获取如下文本框的ID来添加验证器,客户端ID包含生成的字符串,UniqueID也是,但只有ID不包含任何内容,为什么?
Protected Sub GridView1_RowDataBound(ByVal sender As GridView, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
'Manipulate only editing row.
If e.Row.RowType = DataControlRowType.DataRow Then
If sender.EditIndex = e.Row.RowIndex Then
'Search textbox and add validators.
For Each cell As TableCell In e.Row.Cells
If cell.Controls.Count = 1 AndAlso TypeOf (cell.Controls(0)) Is TextBox Then
Dim txt As TextBox = DirectCast(cell.Controls(0), System.Web.UI.WebControls.TextBox)
'txt.ID is nothing...why?
SetValidators(cell.Controls, txt.ID)
End If
Next
End If
End If
End Sub
【问题讨论】:
-
你为什么在代码后面这样做?您可以在表单视图中执行此操作。\
-
大概有20个目标表要编辑,所以想自动生成。
-
您确定在更新模式下执行代码吗?你确定你给TextBox分配了ID??
-
不,我没有将 ID 分配给 TextBoxes。因为 GridView 会自动生成它们。
-
所以在文本框生成块中添加验证器。