You are on page 1of 2

c  



  
Introduction
[ Back To Top ]

When displaying data in a grid, there are instances when you would want the data column not to
be visible to the client and still require it for further processing. This can be achieved by simply
setting the column¶s visibility property to False. This can be done in versions prior to ASP.NET
2.0, but how do you achieve this in ASP.NET 2.0? Read on to find out«

The Problem
[ Back To Top ]

The GridView of ASP.NET 2.0 has replaced the DataGrid and the scenario mentioned above just
does not work in ASP.NET 2.0.

When the column¶s visibility property is set to False, the GridView does not bind the data to the
column. When you try to retrieve data from the hidden column, you get an empty string.

Result? You start debugging your application and end up being lost in the web.

I hope the solution mentioned below saves some of your precious development time.

The Solution
[ Back To Top ]

Add the GridView¶s RowCreated event and set the cell¶s visibility property to False.

Listing 1

ð  
  
   
   
   

  !" 
#$%  
  
 
&% '  ('     ) '
# 
&
  "    #'  
  #' 
  *$  +, 
!  

The GridView¶s RowCreated event gets called after the data is bound to the grid. So the first
column is hidden only after it is databound. It is possible to hide the other columns by changing
the cell index.

In a Nutshell
[ Back To Top ]
In this article you have learned how to hide columns using GridView control using ASP.NET
2.0. Happy coding!

You might also like