Click here to Skip to main content
14,031,710 members
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 12 Feb 2009
Licenced CPOL

Edit Cells in Gridview in ASP.NET

, 12 Feb 2009
Rate this:
Please Sign up or sign in to vote.
This article shows how to edit individual cells in gridview


This article shows how to edit individual cells in gridview in ASP.NET. This example is in Visual Web Developer 2005 Express Edition.

Using the Code

Download the project, unzip it to somewhere on your hard disk. You'll find a database and a gridview (test this project after you finish reading this article).

For this article, you can use the database from the project. If you use any other database, you have to specify a primary key (this is very important).

Steps to Create the Project Manually  

In your project (I suppose you have a database with a primary key):

  • In the design view, drag a gridview from toolbox (if you can't see it, press ctrl+alt+x).
  • Click the GridView SmartTag to open up its Tasklist.
  • Choose data source (your database). Select all from your table. Then next and finish.


  • In the tasklist, click 'Auto Format' and select a scheme. 
  • Check 'Enable Paging'. Go to 'Properties' (press F4) and search for 'Page Size'.


  • In 'Properties', set 'AutoGenerateEditButton' to true.

Edit an Entire Row 

Remember, you can't modify the field which is the primary key. So, we'll edit the fields 'LastName', 'Age' and 'Sport'. For this, we must add the Update statement to our sqldatasource.

  • Click the GridView SmartTag to open up its Tasklist.
  • Click 'Configure Data Source'. at the 'Configure the Select Statement' step, check "Specify a custom SQL statement or stored procedure". Next. Click the 'update' tab and add this code:
    UPDATE [Humans] SET LastName = @LastName, Age = @Age, _
    	sport = @sport WHERE [FirstName] = @FirstName


  • What is @name? These are the parameters that you fill in, when editing the row.
  • The parameter that appears in the Where clause is the primary key of the database. If the Where clause is missing, then all the rows will be updated. 
  • Click Next and Finish. Save(Ctrl+S). On your page, right-click and 'View in browser'.


Edit Individual Cell

We want to edit only the 'sport' cell and we don't want to see the textboxes for the other cells.

  • Click the GridView SmartTag to open up its Tasklist. 
  • Go to 'configure data source' and modify the update statement so it looks like this:


  • Click Next and Finish.
  • In the gridview's tasklist, click 'Edit Columns'. Click the 'LastName' field and set 'ReadOnly' to true.


  • Set 'ReadOnly' to true for the 'Age' field.  
  • Click Ok. Save(Ctrl+S). On your page, right-click and 'View in browser'.



  • 12th February, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Romania Romania
No Biography provided

Comments and Discussions

QuestionMy vote of 4 Pin
Alireza_136217-Mar-13 21:09
memberAlireza_136217-Mar-13 21:09 
GeneralMy vote of 5 Pin
sugumaran srinuvasan6-Nov-11 19:30
membersugumaran srinuvasan6-Nov-11 19:30 
GeneralMy vote of 5 Pin
grivix3-Apr-11 15:41
membergrivix3-Apr-11 15:41 
GeneralMy vote of 1 Pin
Petr Sikula9-Feb-10 0:41
memberPetr Sikula9-Feb-10 0:41 
GeneralMy vote of 1 Pin
Daniel Nutu1-Feb-10 22:31
memberDaniel Nutu1-Feb-10 22:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190419.4 | Last Updated 12 Feb 2009
Article Copyright 2009 by Primejdie
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid