在动态控件的GridView中找不到控件 [英] Can't Find Controls in GridView on Dynamic Controls
问题描述
我有一个gridview,在运行时将文本框添加到每个单元格。但是,我似乎无法使用 findcontrol
访问这些控件。以下是我如何将文本框添加到gridview:
如果e.Row.RowType = DataControlRowType.DataRow然后
For i = 1 To e.Row。 Cells.Count - 1
Dim txtSchedule As New TextBox()
txtSchedule.ID =txtSchedule& i.ToString
e.Row.Cells(i).Controls.Add(txtSchedule)
Next
End If
当我去查找控件时,它说它们是空的:
GridView1.Rows(0).Cells(cellindex).FindControl(txtSchedule& cellindex.ToString)
编辑
问题是,在文本框被填充之后,它会重新创建文本框,因为我已经在创建行中创建了它们
解决方案
在您添加控件的行的单元格内使用FindControl。 GridView1.Rows(0).Cells(cellindex).FindControl(txtSchedule& cellindex.ToString)
I have a gridview where I add textboxes to everycell on runtime. However, I can't seem to access those controls using findcontrol
Here is how I add the textboxes to the gridview:
If e.Row.RowType = DataControlRowType.DataRow Then
For i = 1 To e.Row.Cells.Count - 1
Dim txtSchedule As New TextBox()
txtSchedule.ID = "txtSchedule" & i.ToString
e.Row.Cells(i).Controls.Add(txtSchedule)
Next
End If
When I go to find the controls it says they are Nothing :
GridView1.Rows(0).Cells(cellindex).FindControl("txtSchedule" & cellindex.ToString)
EDIT The problem is that after the textboxes get populated it recreates the textboxes since I have them in row created
Use FindControl within the Cell of the Row that you added the Control:
GridView1.Rows(0).Cells(cellindex).FindControl("txtSchedule" & cellindex.ToString)
这篇关于在动态控件的GridView中找不到控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!