Gridview edit mode rowupdating

To avoid this we need to keep the property Read Only as false, Then in the edit mode nothing will happenes. The reason I use Template Field instead of Bound Field is that, it is very easy to grab those controls in the codebehind if we user labels or textboxes.In case of the bound field’s we need to check what column it is and need to use index of that cloumn, which is little hard and even in future if we change the column order If you see the Last Template Field part in the above code, I am using the link buttons for edit, update, delete and cancel.

gridview edit mode rowupdating-14gridview edit mode rowupdating-30gridview edit mode rowupdating-3

If we use proper command names for the buttons like “EDIT”, “DELETE”, “UPDATE”, “CANCEL” these will also trigger the appropriate Grid View Events.

Ok let’s move on to Code behind what we have to do when user clicks Edit, Delete, Update and Cancel When we click on Edit the On Row Editing event will be fired.

And in each each row, there will be a single column which will be used to modify the selected row.

It will have a single button in read only mode which is "Edit", And when I click on Edit, the row will change into Edit mode.

We will use Template Field, whenever we want to define some custom control in the data bound controls like Grid View, Data Grid or Data Repeater.

If he clicks edit (or) in the edit mode he can be able to see the Textbox.

You can see the C# code below will give the row number whatever you are editing by New Edit Index property.

So Grid View will put the appropriate row into the Edit Mode by assigning row number to its Edit Index property. You can follow any responses to this entry through the RSS 2.0 feed.

I don't need to write any custom code and all the columns I have selected in my query will be appeared as it is in my Grid View.

Ok, Now what my target is, I will have some rows in my Grid View and initially it will be read only.

The editable fields of the row will change into edit mode and the "Edit" button will disappear.