In this article we will look at how to update or delete a record in a database table using a Grid View control.The Grid View control is a tabular databound control but sometimes it is used like a spreadsheet control. NET 2.0 and is an improved version of the Data Grid control. We can use this to display data from a database and edit, sort and select the data.In this demo, I presumed that you already have a basic background on how to create a simple database table. Thanks that cmd do not work fine string id = Grid View1. 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. In addition to just displaying data, the Grid View can be used to edit and delete the displayed data as well.
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. Now you can ask questions directly to me on my new site ASPForums. Net Question Answer site, specially started to allow visitors of this site ask their doubts and queries. Just click the Ask Now button and ask your question now. In this code below code, you see database table columns binding with the bound fields and formatting is provided using the template fields.Introduction The Grid View control displays the values of a data source in a table.Now let’s create a method for executing the Update or Insert. Six of those paramaters basically comes from the Text Box values that were entered in the page. Invalid Cast Exception: Unable to cast object of type 'System. By combining these controls, you can easily set up master-detail views using very little code and sometimes no code at all.From the following chapters you can see some important operations in ASP. 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.