GridView RowUpdating Event

Hi experts, I'm having trouble handling a GridView rowUpdating event.  

I have a page with a gridview like so:

        GridView1.DataSource = datasets.Tables[0];
Key properties on the GridView are:  
   AutoGenerateEditButton="True",  OnRowEditing="GridView1_RowEditing" ,  OnRowUpdating = "GridView1_RowUpdating"

Here's the handlers:

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        GridView1.EditIndex = e.NewEditIndex;
        string EditIndex = GridView1.EditIndex.ToString();

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        GridViewRow row = GridView1.Rows[e.RowIndex];
        if (row != null)
            TextBox t = row.FindControl("TextBox1") as TextBox;
            if (t != null)
                Response.Write("The Text Entered is: " + t.Text);    //  ****this is the problem here****

In the Response.Write statement, I retrieve the value thats is being edited.  To my surprise I get the original value - not the new value entered by the user.  

Example:  Lets say I click the edit button on row 10 of my gridview.  This brings up a templated view of row 10 with the "update" and "cancel" commands in the first column.  I'll change the value inside my editable columm from "Around the Horn" to "Circle the Horns".  Then I click "update".  This fires the rowupdating event - and the text rendered is "The Text Entered is: Around the Horn".  

How is it that I can get the new value so that i can create a parameter from it and handle the event properly?????? please help
Who is Participating?
Dnx_7Connect With a Mentor Commented:
you have to use this :

Ctype(e.Row.Rows(e.RowIndex).Cells("INDEX OF THE TEXTBOX HERE").Controls(0), TextBox).Text

BoggyBayouBoyAuthor Commented:
Thanks a bunch!
thanks for the grade :)
It might be worth noting that I'm doing the same thing and "e.Row" does not exist in my C# .NET 2.0 web application for some reason,  e.RowIndex however does exist so ...

GridViewRow row = ((GridView)sender).Rows[e.RowIndex];

... should get the row you need then you can do ...

string mydata = ((TextBox)row.Cells[e.RowIndex].Controls[0]).Text;

... to get the text from the control.
my bad ...

i put the rowindex in the cell index too.
Remember to replace that with the cell number you need from the rows cell array :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.