Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i am using BoundFields in gridview to bind the data to gridview...In row updating event i am getting old values only.i am not getting newly entered values ...why it is happening like that...
XML
<Columns>
    <asp:BoundField DataField="latitude" HeaderText="Latitude" />
    <asp:BoundField DataField="Longitude" HeaderText="Longitude" />
</Columns>

C#
protected void gvAlerts_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
      GridViewRow row = gvAlerts.Rows[e.RowIndex];
      string Latitude = ((TextBox)(row.Cells[1].Controls[0])).Text;
      string Longitude = ((TextBox)(row.Cells[2].Controls[0])).Text;           
}

Here in latitude and longitude, i am getting the old values only....not getting the newly entered values.....
why it is getting old values only?
Posted
v2
Comments
How you bind the GridView ? Please post theat code here.
s pullareddy 27-May-13 3:15am    
<asp:GridView ID="gvAlerts" runat="server" DataKeyNames="UserAlertId" AutoGenerateColumns="false" AutoGenerateDeleteButton="true" OnRowUpdating="gvAlerts_RowUpdating" OnRowEditing="gvAlerts_RowEditing" OnRowCancelingEdit="gvAlerts_RowCancelingEdit" OnRowDeleting="gvAlerts_RowDeleting" AutoGenerateEditButton="true">

<columns>

<asp:BoundField DataField="latitude" HeaderText="Latitude" />

<asp:BoundField DataField="Longitude" HeaderText="Longitude" />

<asp:BoundField DataField="AlertName" HeaderText="AlertName" />

Please follow my answer.
s pullareddy 27-May-13 3:25am    
yes..i kept (!IsPostBack) now it is getting the newly entered values ...thanks for your answer....

Dear Friend,

In gridview rowupdating event, the row is not actually updated. It handles the event for the row before updates.

Please go through the link below; you will get to know the problem in your code.

GridView.RowUpdating Event

Please don't forget to mark this as your answer if it helps you out.

Regards

Varun Sareen
 
Share this answer
 
Comments
It is a PostBack issue. Please check my answer. RowUpdating should fetch you the new values.
Varun Sareen 27-May-13 4:34am    
Okays dear i am glad that you got the answer though not from mine.
Ok. Thanks.
I think when you click update link, Gridview is binding again before taking new value.

You must have forgotten to use if(!IsPostBack) before GridView.DataBind().

Ideally before binding you should check that like below...

C#
if(!IsPostBack)
{
    // Code to bind the GridView.
}
 
Share this answer
 
Comments
s pullareddy 27-May-13 3:24am    
yes..i kept (!IsPostBack) now it is getting the newly entered values ...thanks for your answer....
Most Welcome. My pleasure... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900