Solved

gridview hiding columns

Posted on 2008-10-29
7
434 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
  • 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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