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.
Forgive me for the variation in my code formatting I'm trying to find the right one.
If we look at this event we can see the Grid View nicely packages for us the new values, old values and the keys for the updating row.
Right now you must be asking yourself how can you get those dictionaries filled out just as if you were bound to a Datasource control?
The good news is you CAN do it(this is what this blog post is all about right? This is probably one of the worst things you can do.
Then we need to override the gridview's Row Updating event.
In this example, this time I used my own database called Sample DB which has Customers Table and basically contains the following field columns: As you have noticed in STEP 2, we have added six Text Box and a Button in the web form in order for us to type the information there and Insert them to the database.
This demo is a continuation of my previous example “Binding Grid View with Data”. When I do an update, and get to the Grid View1_Row Updating, there is no value passed to "ID", and then when I go to the next row for "Company" I get the following error: Specified argument was out of the range of valid values. Text; bit when ichange it to string id =((Text Box) Grid View1. Line 136: Source Error: Line 134: string Um = ((Text Box)Grid View1.
If you are not familiar of binding the Grid View the way then I would suggest looking at my previous example first before you proceed to this example. Parameter name: index Any idea what I need to do to fix this issue?
Create SQL Connection We need a connection with a Microsoft SQL Server database so we can access data and perform an operation on it.
We define a connection in the web.config file and give a name to the connection string.