Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hello friends
 
Here is my code which is not work for gridview row updating
protected void gdUrlDetails_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
    int id = Convert.ToInt32(gdUrlDetails.DataKeys[e.RowIndex].Value.ToString());
    // Label lblUrlId = (Label)_row.FindControl("lblUrlId");
    TextBox txtUrl = (TextBox)gdUrlDetails.Rows[e.RowIndex].FindControl("txtUrl");
    // TextBox txtTitle = (TextBox)_row.FindControl("txtTitle");
    TextBox txtTitle = (TextBox)gdUrlDetails.Rows[e.RowIndex].FindControl("txtTitle");
    objurl.UpdatedDate = Convert.ToDateTime(DateTime.Today);
    objurl.UpdatedBy = Session["session_staffuserid"].ToString();
    objurl.UrlStatus = 1;
    objurl.PageId = Convert.ToInt32(ddlPageName.SelectedValue);
    URLDetails_Data.UpdateForUrlDetails(Convert.ToInt32(id), txtUrl.Text, txtTitle.Text, objurl.UpdatedBy, DateTime.Today, objurl.UrlStatus, objurl.PageId);
    gdUrlDetails.EditIndex = -1;
}
Posted 31-Mar-13 21:05pm
Edited 31-Mar-13 21:12pm
SoMad134K
v3
Comments
pradiprenushe at 1-Apr-13 2:17am
   
You get any exception? Are you getting values for textbox? If yes then need to see UpdateForUrlDetails function.
shinebudy at 1-Apr-13 2:23am
   
When i debug my code the old value display suppose after edit i make catlog1 and the old value display catlog at that time show old value and updating not fire the textbox show open after updating fire

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

USE e.Row.RowState == DataControlRowState.Edit as shown below, your problem may solve
 

protected void gdUrlDetails_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
 if (e.Row.RowState == DataControlRowState.Edit )
 {
int id = Convert.ToInt32(gdUrlDetails.DataKeys[e.RowIndex].Value.ToString());
    // Label lblUrlId = (Label)_row.FindControl("lblUrlId");
    TextBox txtUrl = (TextBox)gdUrlDetails.Rows[e.RowIndex].FindControl("txtUrl");
    // TextBox txtTitle = (TextBox)_row.FindControl("txtTitle");
    TextBox txtTitle = (TextBox)gdUrlDetails.Rows[e.RowIndex].FindControl("txtTitle");
    objurl.UpdatedDate = Convert.ToDateTime(DateTime.Today);
    objurl.UpdatedBy = Session["session_staffuserid"].ToString();
    objurl.UrlStatus = 1;
    objurl.PageId = Convert.ToInt32(ddlPageName.SelectedValue);
    URLDetails_Data.UpdateForUrlDetails(Convert.ToInt32(id), txtUrl.Text, txtTitle.Text, objurl.UpdatedBy, DateTime.Today, objurl.UrlStatus, objurl.PageId);
    gdUrlDetails.EditIndex = -1;
}
}
 

 

 

 
Update: the problem looks like that you have also bind your Edit Item template columns with the data from data table, and when you are getting the data in the code behind you are not getting the updated data which the user updates in edit mode and u still getting the old data. If you remove the Binding from the Edit Item Template fields then your code will work.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 PIEBALDconsult 160
4 CPallini 155
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100