Solved

GridView RowUpdating Event

Posted on 2006-06-11
5
27,618 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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