Click here to Skip to main content
11,798,280 members (77,533 online)
Click here to Skip to main content

How to Hide GridView Cloumn Cell and how retrive value of a hidden cell

, 27 Aug 2007 61.2K 26
Rate this:
Please Sign up or sign in to vote.
Hide and Retrive value of cloumn of a GridView

How to Read value from a hidden Column Cell of GridView using (C#)

1-First step is to create a Project using C#

2-Drag and drop a GridView from the Toolbox on to the Web page and name the GridView to MYGrid.

3-Created The following Columns using BoundField as show below.

Screenshot - P_1.gif

4-Make sure the Grid look like this.

Screenshot - P_2.gif

5-Create a table with the following variable. Where Id is primary key

Screenshot - P_3.gif

6-Add some data to the table

Screenshot - P_4.gif

7-Add a label and textbox to the web page

Screenshot - P_5.gif

8-Create a connection string for example

String Cn="DataBase_.....";

9- Copy this code to the Page_Load

protected void Page_Load(object sender, EventArgs e)


SqlConnection cn = new SqlConnection(Cn);

SqlDataAdapter ad = new SqlDataAdapter("Select * GData from GData" , Cn);

DataSet ds = new DataSet();


MyGrid.DataSource = ds.Tables[0];



10-Add the following to the Web HTMl Page under MyGrid properties

OnRowCreated =" MyGrid _RowCreated" OnRowCommand=" MyGrid_RowCommand"

11-Created the the following method as show below

12-RowCreated Method(This Method is callded to Hide the first cloumn that is Id(Cell 1).

protected void MyGrid_RowCreated(object sender, GridViewRowEventArgs e)


e.Row.Cells[1].Visible = false;


Note:If User need to use sorting then modify the above MYGrid_RowCreated method as follows.

protected void MyGrid_RowCreated(object sender, GridViewRowEventArgs e)


if (e.Row.RowType == DataControlRowType.Header)


e.Row.Cells[1].Visible = false;


if(e.Row.RowType == DataControlRowType.DataRow)


e.Row.Cells[1].Visible = false;



13-RowCommand Method

protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)


if (e.CommandName == "Select")


int index = Convert.ToInt32(e.CommandArgument);

GridViewRow row = MyGrid.Rows[index];

TextBox1.Text = row.Cells[1].Text.ToString();




This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Chief Technology Officer
United States United States
More than 15 years of experience in design, architecture and development of various commercial objects oriented application.Other Specialties

Data Migration:
• MS Access database to SQL 2005/2008
• MS Access database to Oracle
• MS Access database to My SQL
• FoxPro to SQL

Application Migration:
• Converted MS Access application to .net web application (
• Excel Application to .net 3.5 web application
• FoxPro application to .net 3.5
Reporting development and support
• MS access reports
• Crystal reports
• SQL Reports(SSRS)
• DevExpress reports
• Cognos reports
Application development and support
• .net Application web /Win forms
• SharePoint
• MS Access
• Website
• Ecommerce
• Web Services
3rd Party Control Support
• DevExpress
• .netForum
• Telerik
Version controls Support
• Team Foundation Server
• Source Safe

You may also be interested in...

Comments and Discussions

General2 from my side.... Pin
padmanabhan N28-Oct-09 22:35
memberpadmanabhan N28-Oct-09 22:35 
GeneralMy vote of 2 Pin
padmanabhan N28-Oct-09 22:34
memberpadmanabhan N28-Oct-09 22:34 
GeneralMy vote of 2 Pin
Donsw26-Nov-08 16:51
memberDonsw26-Nov-08 16:51 
GeneralRedundant Pin
fergara12-Sep-08 3:12
memberfergara12-Sep-08 3:12 
GeneralRe: Redundant Pin
T.Ashraf12-Sep-08 3:17
memberT.Ashraf12-Sep-08 3:17 
GeneralHidden cell value problem Pin
abdulqadar3-Apr-08 1:05
memberabdulqadar3-Apr-08 1:05 
GeneralThanks! Pin
Eceg16-Nov-07 17:59
memberEceg16-Nov-07 17:59 
GeneralVote Early and Often Pin
Humble Programmer6-Jul-07 5:55
memberHumble Programmer6-Jul-07 5:55 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151002.1 | Last Updated 27 Aug 2007
Article Copyright 2007 by T.Ashraf
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid