• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

How to hide Record ID in gridview and still access the value?

I have a gridview that peforms actions based on the record id of the row, called RecID.  The functions work great when I have the RecID visible in the grid, but when I set visible=false, it fails on this line:

int RecID = Convert.ToInt32(gvTracks.Rows[ii].Cells[0].Text);

How do I reference the value when it's set to visible=false?  Thanks!
0
JT_SIRO
Asked:
JT_SIRO
3 Solutions
 
MlandaTCommented:
The GridView control has the functionality to allow multiple DataKey values to be assigned to it using the DataKeyNames property. However, the method of retrieving a DataKey that is not the primary key is, for the most part, undocumented. The Values property will allow you to get any DataKey value.

VB.NET
GridView.DataKeys(Index1).Values(Index2)

Open in new window


C#
GridView.DataKeys[Index1].Values[Index2]

Open in new window


Where GridView is the ID of the GridView control, Index1 is the index of the current row in the GridView, and Index2 is the name of the DataKey.

http://forums.asp.net/t/951615.aspx


http://authors.aspalliance.com/aspxtreme/sys/web/ui/webcontrols/gridviewclassDataKeys.aspx
0
 
Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
You can use any of following

If you hide the column with css rule display:none, as opposed to setting Visible property to false, you can access it as any other column.

or Use DataKeys with DataKeyNames


0
 
Kamal KhaleefaInformation Security SpecialistCommented:
make the column visible=false
0
 
aswathiCommented:
hi
Make the column visible just before databind and  make it invisible just after it.
Also set Visible = true in the property of that column in grid

gvTracks.Columns[0].Visible = true;   // index of column RecID
gvTracks.DataSource = datatable;
gvTracks.DataBind();
gvTracks.Columns[0].Visible =false;;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now