Solved

GridView RowUpdating Event

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

626 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