Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GridView RowUpdating Event

Posted on 2006-06-11
5
Medium Priority
?
27,637 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
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
Dnx_7 earned 2000 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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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 …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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