AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 is there a way to call GridView1_RowCancelingEdit event in GridView1_RowUpdating event
Posted by archana on  12/11/2009 3:09:36 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Hi all, i am actually working on a simple 3 tire architecture project in asp.net 2.0..
i have a gridview in my form...when i update the gridview the data gets updated but then it stays in the edit mode itself even though i have set the gridview1.EditIndex=-1;
so i tried calling the GridView1_RowCancelingEdit event in GridView1_RowUpdating event,can any one help me on this...
here is my code..

protected void UpdateRecord(object sender, GridViewUpdateEventArgs e)
{
string pid = GridView1.Rows[e.RowIndex].Cells[2].Text;
int personId=Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());

int intResult=0;
GridViewRow row;
row=GridView1.Rows[e.RowIndex];

TextBox tFN = (TextBox)row.FindControl("txtFName");
TextBox tLN = (TextBox)row.FindControl("txtLName");
TextBox tAge = (TextBox)row.FindControl("txtAge");
try
{
intResult=objbal.Update(tFN.Text,tLN.Text,Int32.Parse(tAge.Text),personId);
if(intResult>0)
{
lblMessage.Text="Records updated successfully";
}
else
{
lblMessage.Text="Records could not updated";
}

}
catch(Exception ex)
{
lblMessage.Text=ex.Message.ToString();
}
finally
{
objbal=null;
}

GridView1.EditIndex = -1;

GridViewCancelEditEventArgs e1 = new GridViewCancelEditEventArgs(e.RowIndex);
this.GridView1_RowCancelingEdit(sender, e1);
BindData();



}

but even then its still in the edit mode..i am using template columns...

Post Your Reply Post New Question

 Viewer's Reply
GridView - Make EditIndex = -1 After Update
Answered By Moderator1 on 12/11/2009 10:10:56 PM
Hi,

Everything is fine with your code. After you update successfully, you need to do as below,

GridView1.EditIndex = -1;
BindGrid();

Remove the below 2 lines of code,
"GridViewCancelEditEventArgs e1 = new GridViewCancelEditEventArgs(e.RowIndex);
this.GridView1_RowCancelingEdit(sender, e1); "

Rest is fine.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Website Magazine
Simply JavaScript - Free 150 Page Preview!
Backup and Recovery Best Practices for Microsoft SQL Server 2005