Click here to Skip to main content
Licence 
First Posted 6 Jul 2007
Views 42,367
Bookmarked 26 times

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

By | 27 Aug 2007 | Article
Hide and Retrive value of cloumn of a GridView

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

1-First step is to create a Asp.net 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();

ad.Fill(ds);

MyGrid.DataSource = ds.Tables[0];

MyGrid.DataBind();

}

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();

}

}

License

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

T.Ashraf

Technical Lead
TANVTECH
United States United States

Member

More than 10 years of experience in design, architecture and development of various commercial objects oriented application using C# 3.5, ASP.net, relational database like SQL 2008, Oracle, MySQL and SharePoint. Experienced in client-server application development, data security management system, e- commerce, automation processes, claim payment systems, file system and tracking systems, also has very good exposure to the entire software development life cycle.
Tanvtech.com
http://tanvtech.com/Articles/MyFirstSSRSReport.aspx
http://tanvtech.com/Articles/MyFirstSSRSSubReport.aspx
http://tanvtech.com/Articles/MyFirstWcfArticle.aspx
http://tanvtech.com/Articles/MyFirstWcfClientArticle.aspx

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
General2 from my side.... Pinmemberpadmanabhan N22:35 28 Oct '09  
GeneralMy vote of 2 Pinmemberpadmanabhan N22:34 28 Oct '09  
GeneralMy vote of 2 PinmemberDonsw16:51 26 Nov '08  
GeneralRedundant Pinmemberfergara3:12 12 Sep '08  
GeneralRe: Redundant PinmemberT.Ashraf3:17 12 Sep '08  
GeneralHidden cell value problem Pinmemberabdulqadar1:05 3 Apr '08  
GeneralThanks! PinmemberEceg17:59 16 Nov '07  
GeneralVote Early and Often PinmemberHumble Programmer5:55 6 Jul '07  

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.

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