Solved

gridview hiding columns

Posted on 2008-10-29
7
441 Views
Last Modified: 2013-12-17
I have a gridview for which I am writing my own update/edit code.

In order that my SQL updates the right row I must use the primary key (which is a unique number). I need access to the primary key, but do not want to show it in my table. Is it possible to high columns in gridview, but still access the data?
0
Comment
Question by:Mr_Shaw
[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
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22831583
GridView1.Columns[2].Visible = false;

CodeSnip: Hiding Columns using GridView
http://aspalliance.com/950
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 22831599
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.Cells.Count >= 1)
        e.Row.Cells[1].Visible = false;
}

Assuming you want to hide the second column in your automatically generated GridView.

0
 

Author Comment

by:Mr_Shaw
ID: 22831697
The code;

GridView1.Columns[2].Visible = false;

this works for hiding the Edit/Delete buttons, but for the data which I binding from SQL server nothing gets hidden.

0
Stressed Out?

Watch some penguins on the livecam!

 
LVL 53

Expert Comment

by:Dhaest
ID: 22831743
Did you try the RowDataBound-event ?
0
 

Author Comment

by:Mr_Shaw
ID: 22831913
It all works...

I final quick question is... for my Edit/Delete button to work I have to click them twice. How do I stop this?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22832075
If it is a primary key, then you don't even need to have a column for it in GridView. GridView has a property called DataKeyNames, all you need to do is to set DataKeyNames="primaryKeyFieldName", and later you can retrieve the primary key by using GridView1.DataKeys(index).Value.
0
 

Author Closing Comment

by:Mr_Shaw
ID: 31511189
Thanks all works now
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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