Gridview updating database

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.

With the help row variable, I am going to find all the controls placed under that row in edit mode using Find Control property.

gridview updating database-14gridview updating database-51

In this method, I am specifying the Edit Index property of the Grid View to -1.

As there is no row at -1 position so Grid View will be shown in normal mode.

Connect me on | | Hello....

NET, like how to insert, delete and update record in Grid View control.

You can notice that I have kept Required Field Validator too inside the Edit Item Template as I want the textbox to be validated for empty data.

In the same way you can put any kind of Validation controls inside Edit Item Template to validate the form element while user will click Update link.

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.

In practical scenario you should use your existing architecture to populate and update the data.

Hope this article helps to begin working with Grid View control. Right now I have a label turn to visible true and a message when someone either edits or deletes something successfully.

Comments are closed.