Gridview RowUpdating找不到控件

时间:2012-06-01 04:57:55

标签: vb.net gridview findcontrol

正如标题所说,我无法找到我想要的控件。

这是GridView:

    <asp:GridView ID="gvInfo" runat="server" AutoGenerateColumns="false" AutoGenerateEditButton="true">
        <Columns>
            <asp:BoundField DataField="filename" HeaderText="Filename" SortExpression="filename" />
            <asp:ButtonField ButtonType="Button" CommandName="Select" 
                HeaderText="Move File" ShowHeader="True" Text="Move File" />
        </Columns>
    </asp:GridView>

这是背后的代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        ShowGV()
    End If
End Sub

Protected Sub gvInfo_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvInfo.RowEditing
    gvInfo.EditIndex = e.NewEditIndex
    ShowGV()
End Sub

Protected Sub gvInfo_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvInfo.RowCancelingEdit
    gvInfo.EditIndex = -1
    ShowGV()
End Sub

Protected Sub gvInfo_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvInfo.RowUpdating
    Dim row = gvInfo.Rows(e.RowIndex)
    Dim Test As String = CType(row.FindControl("filename"), TextBox).Text
    Response.Write(Test)

    gvInfo.EditIndex = -1
    ShowGV()
End Sub

非常感谢任何帮助。

感谢。

1 个答案:

答案 0 :(得分:2)

尝试

CType(row.Cells(0).Controls(0), TextBox).Text
'change index of `cell(0)` to required column index (column index starts from 0)

将所需列转换为TemplateField并使用

CType(row.FindControl("LabelNamein'EditItemTemplate'"), TextBox).Text