Updating data in gridview
Till now our Grid View is ready to be populated, now let’s write a method to populate the Grid View.To populate the Grid View, I am calling Bind Data() method from Page_Load event after checking Is Post Back property of the page, so the Grid View will only be populated when there is no postback on the page (when the page loads for the first time).For updating records click button “Edit” and change Text Box Data and you can select new photo of employee.For example in place of age“28”, updated with “30” and in place of salary “50000”, updated with “55000”, then click button “Update”. With the help row variable, I am going to find all the controls placed under that row in edit mode using Find Control property.After finding the controls I am using them to pass their values to the parameter of the Sql Command object that is ultimately updating the records into database.To get the Primary key, I have used Data Keys property of the Grid View with the index of the row, being edited and stored into a integer variable after parsing.
If you have a feedback or suggestion, please do write to me. Full Name: Sheo Narayan Member Level: Honorary Platinum Member Status: Administrator Member Since: 7/8/2008 PMCountry: India Regards, Sheo Narayan MVP, Author, Writer, Mentor & architecting applications since year 2001. What would you do if you wanted to have an event trigger when you click on the "cancel" button during the delete process. When a person starts to delete another item and decides to cancel the delete, the old message from the previously edited or deleted item still shows. ya,its how can I use the button field for the edit and delete in the template field.suppose i used that controls,what kind of events could I used for edit successfully?
In this method again, I am getting the primary key value using Data Keys property of the Grid View and using it to delete the records from the database.
After successfully deleting records, again I am calling Bind Data() method to rebind the Grid View.
Please note that when you will not bind the data again, Grid View will not change in edit mode.
When Cancel link is clicked on Grid View in edit mode, On Row Canceling Edit event will fire that will call Cancel Record method.