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. Please help me with writing a Row Updating function in C#, I don't know how to grab the current field's value and also get the old value for one of keys (which is Project Name for editing) of the selected row. the idea wa to don't allow binding the grid view after a post back. 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. 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.
So what you need to do is store the data source (maybe in Session) and only bind rebind the data when you absolutely need to (Like during the Is Not Post Back) Do you understand? We use the Row Updating event of Grid View to update the record in the database table.We get the Id value using the row index and another Text Box value is also retrieved.The very first column of the grid is a bound data item that I converted to a template column. This column has a label called lbl Disc ID which gets populated on the gridview control correctly. protected void gridview_Row Updating(object sender, Grid View Update Event Args e) { string Disc Descrip = Convert.