Solved

How do I hide a column of a Gridview at runtime

Posted on 2011-02-15
8
477 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

862 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

23 Experts available now in Live!

Get 1:1 Help Now