Solved

GridView RowUpdating Event

Posted on 2006-06-11
5
27,617 Views
Last Modified: 2011-08-18
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];
        GridView1.DataBind();
     
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();
        GridView1.DataBind();
    }

    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
0
Comment
Question by:BoggyBayouBoy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
Dnx_7 earned 500 total points
ID: 16881936
you have to use this :


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

regards
0
 
LVL 1

Author Comment

by:BoggyBayouBoy
ID: 16886710
Thanks a bunch!
0
 
LVL 2

Expert Comment

by:Dnx_7
ID: 16892176
thanks for the grade :)
0
 
LVL 4

Expert Comment

by:Wardy_01
ID: 24314584
It might be worth noting that I'm doing the same thing and "e.Row" does not exist in my C# .NET 2.0 asp.net 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.
0
 
LVL 4

Expert Comment

by:Wardy_01
ID: 24314606
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 :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 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