Gridview1 rowupdating old values

6854933580_2c8b688306_z

After you've created a layout with a data control of your choice and eventually bound them to some datasource, you almost always want to get that data back out of them(and why wouldn't you, its your data).One thing you'll learn about developing webpages is that its like petting a porcupine (yikes).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.Now we access this connection string on the page so we can open a connection with the relation database. The first one accesses the connection string and the other is for the SQL connection.Now we define a method for opening a connection with the relation database and returns a SQL connection object depending on the connection string that is passed as a parameter of the Sql Connection class constructor.Click on the "Advanced" button and check the "Generate INSERT, UPDATE and DELETE statements" checkbox (Figure 3). Now that you have configured the SQL Data Source control let's bind it with a Grid View control. Open its smart tag and configure it as shown in Figure 4.

Most of the data controls have events ending in ing and ed e.g. In most of the event handlers of the ing events it is easy to get the values from the event args.Unfortunately these dictionaries are only filled out if you are bound to a datasource control :(.So that means when you bind to some raw collection and hook up to the Data Source property then call databind, if you try to handle the delete or update events these dictionaries are going to be empty.Delete a Record We can delete a record from the database table by clicking on the delete button that is in the Delete column of the Grid View.We first of all create a Stored Procedure that gets the Id of an employee as a parameter from the Grid View on whichever row the user clicked. In this event, first we get the datakey value that is the id of an employee of whichever row the user clicked and that id is passed as a parameter to the Stored Procedure. According to the above, in these three operations we use three events of the Grid View for each operation.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.

You must have an account to comment. Please register or login here!