Updating dataset with gridview

After the Data Source property is set, the Data Bind() method is called explicitly.

We need to place the following code in a page to create a Grid View control.

In this article, I am going to take a simple database table that has following fields: Auto ID - Int, Auto Increment, Primary Key Page Name - Varchar(50) Page Description - Varchar(500) Active - Bit(1) In this article, I am not going to explain the workings of Sql objects but focusing on the events and methods of the Grid View that will help us in updating and deleting the records.

Now let’s start with putting the Grid View on page. Data Key Names="Auto ID" Auto Generate Edit Button="True" On Row Editing="Edit Record" On Row Canceling Edit="Cancel Record" On Row Updating="Update Record" Cell Padding="4" Header Style-Horizontal Align="left" On Row Deleting="Delete Record" Row Style-Vertical Align="Top" Fore Color="#333333" Grid Lines="None" In the above code, I have kept Auto Generate Columns as false so that Grid View will not render all the fields of the data source automatically.

User continues navigating page, but after first load, no more DB connection is made, grid is filled from Data Table Session object. Sometime, user sets Grid View to edit mode and makes some changes. Your best bet is probably to manually update the table stored in Session state in Row Updating or Row Command event.

I somehow imagine that there must be a way to reflect user's change on Gridview to Data Table Session object (NOT to actual DB) So when user continues navigating page, he will see updated data (since Data Table is Session-wide) however the actual DB is not updated. the one set by by Data Source ID instead of Data Source).

The goal was to let users check off the radio buttons without having to put the row in edit mode.

updating dataset with gridview-7

As an example, I recently had a question from a developer who was creating a survey.All the above steps happen in the Page_Load() method.After creating the dataset, we can bind the Grid View with a dataset.So I have to specify how I want them to appear in the normal view and edit view.That’s why I have placed different templates like Item Template (for normal view) and Edit Item Template (for edit view).I will be using Sql objects directly into methods to keep the example simple and straight forward.


Leave a Reply