Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

gridview hiding columns

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
Mr_Shaw
Asked:
Mr_Shaw
  • 3
  • 3
1 Solution
 
DhaestCommented:
GridView1.Columns[2].Visible = false;

CodeSnip: Hiding Columns using GridView
http://aspalliance.com/950
0
 
DhaestCommented:
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
 
Mr_ShawAuthor Commented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DhaestCommented:
Did you try the RowDataBound-event ?
0
 
Mr_ShawAuthor Commented:
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
 
prairiedogCommented:
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
 
Mr_ShawAuthor Commented:
Thanks all works now
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now