Working with GridView Hidden Column in ASP.NET

No.of Views729
Bookmarked0 times
Downloads 
Votes0
By  Pankaj Kumar Gupta   On  07 Feb 2011 06:02:23
Tag : ASP.NET , Grid Controls
This article demonstrating how to work with GridView Hidden Column in ASP.NET
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

When a Gridview column's visibility is set to False, then the Grid does not bind data to the column, and thus when you try to retrieve data from the hidden column in the code-behind, it either blows up or returns an empty string.

Maybe you don't need it

It's likely that you don't need the column, at all. If it's not used in your Update statement, Insert statement, or in the code behind, then just remove it. If you are using Table Adapters, then remove the column out of the TableAdapter.

Need it in the Code Behind

If you really need it, don't hide the column, remove it as a column,

Image Loading

and then add the column name to the DataKeyNames Collection of the Gridview.

Image Loading

You can now access these columns in the special DataKey collection of the Gridview, i.e. Gridview1.Datakeys(iRow).Values

You need to pass this back to SQL

If you actually need to pass this back to SQL (via table adapters) then you have to configure the table adapters to accept the column.
All columns in the DataKeyNames get the "Original_" prefix as defined in the ods property

OldValuesParameterFormatString="original_{0}"

Modify the Update Parameter Collection

Image Loading

Such that the hidden column expects the prefix (just like your Primary Key column was done automatically)

Image Loading

Lastly edit the actual T-SQL to expect the parameter with the prefix.

Image Loading

That's all. now you can use the hidden column in Gridview.Hopes help and thank you for reading.

 
Sign Up to vote for this article
 
About Author
 
Pankaj Kumar Gupta
Occupation-Software Engineer
Company-Miri Infotech (P) Ltd, India
Member Type-Junior
Location-India
Joined date-27 Oct 2010
Home Page-www.codegain.com
Blog Page-codegain.com
- I am working with Miri Infotech (P) Ltd, India as Senior Software Engineer. - Having 5+ years experience in .NET Technologies (ASP.NET, C#.net, VB.net, SQL Server, XML, Web Services, MS Dynamics CRM, SharePoint). - I have masters M.Sc-Computer Science, M.Tech-Information Technology with Honours. - I have completed MCP, MCSD.NET, MCAD, MCDBA SQL Server, MCTS, MCPD-EAD - Microsoft Certified Professional & Technology Specialist - Obsessed in OOP, MVC, MVP style design and programming. - Designing and developing the client/server applications for a number of doimains. - Designing and implementing Business Planning Tools & Applications. - Good understanding of formal software engineering tools & technologies.
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top