Capturing the TextBox data using RowCommand from a Gridview Control

Posted on 2009-04-24
Last Modified: 2012-05-06

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

Question by:DEWebWorks
    LVL 14

    Accepted Solution


    Make sure that you are not rebinding the grid again during postback.

    Author Closing Comment

    You're my hero!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now