• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 709
  • Last Modified:

Capturing the TextBox data using RowCommand from a Gridview Control


I am trying to access the data in a textbox control from my RowCommand sub. Here is my Gridview snippet:

                <asp:BoundField DataField="tripEventID" HeaderText="Code" SortExpression="tripEventID" ItemStyle-HorizontalAlign="Left" ></asp:BoundField>
                <asp:TemplateField HeaderText="Entertainment" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                        <asp:TextBox ID="txtOtherExpense" runat="server" style="width:100px;" Text='' />

and below is my RowCommand vb code. My tripEventID is coming across fine. If I set a value to my textbox in code, it works fine - but then I can't get what the user entered. Any suggestions?

Select Case e.CommandName
            Case "Save"
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                ' Retrieve the row that contains the button clicked
                ' by the user from the Rows collection. Use the
                ' CommandSource property to access the GridView control.
                Dim tmpGridView As GridView = CType(e.CommandSource, GridView)
                Dim row As GridViewRow = tmpGridView.Rows(index)
                '---get trip event id
                Dim tmpTripEventID As String = Server.HtmlDecode(row.Cells(5).Text)
                '---find the expense value
                Dim tmpTxtBox As TextBox
                Dim textBoxText As String = CType(row.FindControl("txtOtherExpense"), TextBox).Text
                tmpTxtBox = CType(row.FindControl("txtOtherExpense"), TextBox)
                Response.Write("<br>Here:" & index & ":" & tmpTripEventID & ":" & textBoxText)
            Case Else
        End Select

Open in new window

1 Solution

Make sure that you are not rebinding the grid again during postback.
DEWebWorksAuthor Commented:
You're my hero!

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now