Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I hide a column of a Gridview at runtime

Posted on 2011-02-15
8
Medium Priority
?
483 Views
Last Modified: 2012-05-11
I am creating a gridview at runtime but don't want all the columns to be shown, ie the key information for the row of data I am showing.  I know I can do this

gridview1.column.item(0).visible = false

but although the column is not shown it also does not have the data in the column either and since I need to know the key data for processing the selected item from the grid, the above does not work for me
0
Comment
Question by:keymac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 13

Expert Comment

by:Rahul Agarwal
ID: 34903664
Right this code in the GridView1_RowDataBound Event and hide the column. In Controls(6) the 6 is number of column to be Hide on runtime.

If e.Row.RowType = DataControlRowType.Header Then
         e.Row.Controls(6).Visible = False
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
         e.Row.Controls(6).Visible = False
       End If
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34903884
To hide a column at runt time you can hook up to the GridView’s RowDataBound event and set the Visible property of the cell you want to hide to false:   protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[0].Visible = false; }...
0
 

Author Comment

by:keymac
ID: 34903952
As I said in the question, that approach dos not work.  I need the column to be hidden not invisible.  If it is invisible it is not available as data in the grid, ie I want the column to still have data bound to it but to be hidden to the viewer.
0
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34904011
have you tried this

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[0].Visible = false;
0
 
LVL 20

Accepted Solution

by:
informaniac earned 2000 total points
ID: 34904033
Just use d the Datakeyname property of the gridview to store the value of key u use 4 processing the row.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34904034
in vb.net

Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs)
      e.Row.Cells(0).Visible = False
End Sub
0
 
LVL 20

Expert Comment

by:informaniac
ID: 34904037
Just use the Datakeyname property of the gridview to store the value of key u use 4 processing the row.
0
 

Author Closing Comment

by:keymac
ID: 34904412
Magnificent
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question