Datakeys in gridview rowupdating

Posted by / 30-Jul-2017 09:27

Datakeys in gridview rowupdating

Please keep in mind that there are many different ways to update the database using the Grid View control depending on the type of data you are updating and the functionality the user need and there are many solutions to achieve the same end result.In the above tutorial I tried to give you one of the easiest solutions and I hope you can go explore Grid View control editing further after learning the basics from this tutorial. A datakey represents the primary key field or field of a record that can uniquely identify it in a data-bound control. Row Index represents the index of the particular row.Many a times in our applications we use primary keys to get control of the particular record in the gridview. To do this we first need to obtain the reference of the current row by using its index no as shown in the first line below.By using the Grid View Row object we can find the reference of any control in the row in which user is editing the data.For this situation, many developers use invisible columns (Hidden columns) in the gridview to identify that row. We can achieve the same functionality using Datakeys.

I am using Template Field’s Item Template and Edit Item Template for providing read only and editing interface of the same column in the Grid View.This collection only requires the row index no and it will give us the primary key.Last line of the following code is calling a local method for updating the database and passing all the parameters to this method.The visitors to a web site can typically be divided into two groups: the users and the administrators.In data driven web sites, users are normally allowed to view data and administrators are allowed to add, edit or delete data.

datakeys in gridview rowupdating-15datakeys in gridview rowupdating-83datakeys in gridview rowupdating-40

In this example, I am going to retrieve values from categories table of Northwind database. Drag a Grid View into the Web Form and assign Data Key Names property with the primary key column i.e. In the gdview_Row Editing and gdview_Row Deleting event, we have used the below code to retrieve categoryid from datakey of Grid View, int catid = int.

One thought on “datakeys in gridview rowupdating”

  1. Except for that information which is in the public domain or for which you have been given permission, you will not copy, modify, publish, transmit, distribute, perform, display, or sell any such proprietary information. COM OR ITS REPRESENTATIVES, OR OTHERWISE WITH RESPECT TO THE SERVICE. COM SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NONINFRINGEMENT. COM BE LIABLE (i) TO YOU FOR ANY INCIDENTAL, CONSEQUENTIAL, OR INDIRECT DAMAGES (INCLUDING, BUT NOT LIMITED TO, DAMAGES FOR LOSS OF DATA, LOSS OF PROGRAMS, COST OF PROCUREMENT OF SUBSTITUTE SERVICES OR SERVICE INTERRUPTIONS) ARISING OUT OF THE USE OF OR INABILITY TO USE THE CHRISTIANCAFE. COM OR ITS AGENTS OR REPRESENTATIVES KNOW OR HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR (ii) TO ANY PERSON OTHER THAN YOU.