Updating with gridview

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.

string connetion String = "YOUR_CONSTR" ; string upd Stmt = "UPDATE Quantity set [email protected]_pro4, [email protected]_pro5, [email protected]_profile5 " "where [email protected] Name"; using (Sql Connection cnn = new Sql Connection(connetion String)) I don't see any instance of Sql Connection created!?

Something like Sql Connection con = new Sql Connection(CON_STR) or perhaps a using like in my example. Make sure the parameters on the update match the field names (@branch Name, @Parent Id). Giving me an error in the browser: Must declare the scalar variable "@Locations".

As you may have guessed, when creating an editable Grid View whose data comes from an Object Data Source, the underlying data access layer class must provide an appropriate Update method.

One note will be helpful for you, while describing Columns in Grid View if you are using a boundfield then create objects of the control using cells[index] in the rowupdateing event of Grid View, but if you are using controls itself like Label or textboxes etc then use Fincontrol("stringid").

Database Table Structure We are using an "EMPLOYEE" table so the "EMPLOYEE" table design is: Design of Grid View We design a Grid View with which we can perform update and delete operations.

Here we can update Name, Emp_Code and Emp_Age fields depending on the Id field of the "EMPLOYEE" table.

An editable Grid View contains an additional column with an Edit button in each row.

When the end user clicks on an Edit button that row becomes editable, causing the Edit button to change to Update and Cancel buttons and the other columns to become Text Boxes.

Search for updating with gridview:

updating with gridview-41updating with gridview-64updating with gridview-6

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “updating with gridview”