Solved

How do I hide a column of a Gridview at runtime

Posted on 2011-02-15
8
480 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: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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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