Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends

Here is my code which is not work for gridview row updating
C#
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
Updated 31-Mar-13 20:12pm
v3
Comments
pradiprenushe 1-Apr-13 2:17am    
You get any exception? Are you getting values for textbox? If yes then need to see UpdateForUrlDetails function.
shinebudy 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

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


C#
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.
 
Share this answer
 

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