Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to make the row in normal mode after updating

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.

alt text

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
            }
        }
like image 969
Ananth Avatar asked Jan 22 '11 18:01

Ananth


1 Answers

set GridView1.EditIndex = -1;before this.StaticNoticeGridView.DataBind();in the method StaticNoticeGridView_RowUpdating

like image 181
Vijay Sirigiri Avatar answered Oct 31 '22 20:10

Vijay Sirigiri