Solved

How do I hide a column of a Gridview at runtime

Posted on 2011-02-15
8
476 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 20

Accepted Solution

by:
informaniac earned 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now