Solved

gridview hiding columns

Posted on 2008-10-29
7
431 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

21 Experts available now in Live!

Get 1:1 Help Now