?
Solved

gridview hiding columns

Posted on 2008-10-29
7
Medium Priority
?
443 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 2000 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
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

 
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

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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