2

As the title says I am unable to find the control I want.

This is the 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>

This is the code behind:

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

Any help is much appreciated.

Thanks.

Rambomst
  • 653
  • 2
  • 10
  • 28

1 Answers1

2

Try

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

or

convert required column to a TemplateField and use,

CType(row.FindControl("LabelNamein'EditItemTemplate'"), TextBox).Text 
Nalaka526
  • 11,278
  • 21
  • 82
  • 116
  • The first bit just returns "" With the second bit what do you mean by TemplateColumn? – Rambomst Jun 01 '12 at 05:17
  • @Rambomst Sorry about the incorrect answer. I have updated it now, first method should work. – Nalaka526 Jun 01 '12 at 05:43
  • TemplateColumn : http://www.asp.net/web-forms/tutorials/data-access/custom-formatting/using-templatefields-in-the-gridview-control-cs – Nalaka526 Jun 01 '12 at 05:46