I have a gridview with "Edit Update Cancel" command field. When I click Edit, all the columns in the particular row becomes editable and when I click update, the Table is updated based on the new values. Then the Gridview is binded with the updated datatable. But the "Update Cancel" button still remains.
Once the row , has been updated, the "Update Cancel" button has to be changed to "Edit" So how is that made possible.
Thanks in Advance
This is the code for updating and displaying the updated data
protected void StaticNoticeGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
//Gets the updated value from GridView
string id = StaticNoticeGridView.Rows[e.RowIndex].Cells[0].Text;
string updatedItem = e.NewValues[0].ToString();
string updatedURL = e.NewValues[1].ToString();
//Updated the Database
StaticNoticeController staticNoticeController = new StaticNoticeController();
int rocordsAffected = staticNoticeController.UpdateStaticNoticeData(updatedItem, updatedURL, id);
//Gets the updated datatable and binds the Gridview again
if (rocordsAffected == 1)
{
this.StaticNoticeGridView.DataSource = null;
this.StaticNoticeGridView.DataSource = staticNoticeController.GetStaticNoticeData();
this.StaticNoticeGridView.DataBind();
}
}
catch(SystemException ex)
{
//ToDo: Log the Exception
}
}
set GridView1.EditIndex = -1;before this.StaticNoticeGridView.DataBind();
in the method StaticNoticeGridView_RowUpdating
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With