Gridview Row Editing Updating And Deleting

Posted on -
Gridview Row Editing Updating And Deleting Rating: 5,0/5 1322 votes

I'll bind the GridView control with a database table using SqlDataSource. Meanwhile, you can go through the below link for an overview of how data binding is done using SqlDataSource. Start Microsoft Visual Studio and select File - New - Web Site from the top menu. Add a new website and in the Default.aspx select the Design tab situated at the left bottom. In the design mode, select the Toolbox. From the Toolbox, drag and drop a GridView and SqlDataSource control. Attach the GridView with the SqlDataSource control, the way we have shown the link above.


After you have run the website, you will see the GridView showing details of employees in tabular format. We have selected four columns from table. GridView Edit (Update) Row To edit data in a particular row, add AutoGenerateEditButton and set DataKeyNames='EmpID' to the GridView control. The DataKeyNames field will be used in the SQL query to edit the employee details. This will add an Edit link button at the beginning of all the rows in the GridView. Clicking the link button will trigger a PostBack to the server requesting to edit the row values. As I have mentioned earlier, the GridView shows four columns and I want to edit selected columns only, let’s say, the Mobile Number and Email Address.

May 01, 2008 jeevanmummadi plz send me sample code for gridview edit and update row. If using ADO.NET.

Deleting Rows In Word

Gridview Row Editing Updating And Deleting

Therefore, first set ReadOnly='true' for the fields EmpID and EmpName. In, add the UpdateCommand property, which will have an SQL Update command or a procedure to update the selected row’s data. Add two parameters (or fields) inside property. Delete a GridView Row Similar procedure must be followed to delete one row at a time.


Just add AutoGenerateDeleteButton='true' in the GridView control. In the SqlDataSource add the below property and parameter. There is hardly any code to be written to do these transactions. All we need is to write the SQL queries according to our need.

However, there is a drawback when deleting a particular row. If a user clicks the delete button, the page will post back the delete command and the query is executed, which deletes the entire row. ( Without any warning). It can be very disturbing if the row was mistakenly deleted. The lost data cannot come back. Also Read: To cease these mistakes from happening, we need a confirmation (yes or no) before deleting any row in the GridView.

To accomplish this, set AutoGenerateDeleteButton='false' or remove it entirely. Delete a GridView Row with a Confirmation In the Column section of the GridView we will add control, which will have a client script (Confirm). It will show a popup confirmation message and allows the user to either go with the delete command or negate it. GridView Edit and Delete Row <%-ADD THE DELETE LINK BUTTON-% Delete <%-DATA BOUND COLUMNS-% <%-THE SQL DATA SOURCE CONNECTED WITH THE GRIDVIEW-%

(UserID, Password etc.).