[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Howto Hide Autogenerated Column in ASP.NET DataGrid

Posted on 2006-11-01
5
Medium Priority
?
1,992 Views
Last Modified: 2012-06-22
Greetings

I am binding a DataGrid to a DataTable and letting the DataGrid automatically
generate the columns based on the DataTable columns. I have assigned
my DataKeyField to one of the columns on the DataTable and all works
well. However, I would like to hide the column in the DataGrid corresponding
to the DataKeyField. Can I do this, and if so, how ?

code:
                        dgPubList.DataSource = dTable;
                  dgPubList.DataKeyField = "Publication ID";
                       // possible code here to hide the column  ?
                  this.dgPubList.DataBind();

Thanks
Jeff
0
Comment
Question by:jmuldrum
[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
5 Comments
 
LVL 5

Expert Comment

by:hfpon
ID: 17854776
Think reversely.

1. Stop the auto-column generating
2. Show whichever columns you want them to appear

FOr example
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="Column1" HeaderText="Column1" SortExpression="Column1" />
                <asp:BoundField DataField="Column2" HeaderText="Column2" SortExpression="Column2" />
                <asp:BoundField DataField="Column4" HeaderText="Column1" SortExpression="Column4" />
             .
             .
             .

            </Columns>
        </asp:GridView>
0
 
LVL 10

Accepted Solution

by:
anv earned 1500 total points
ID: 17855589
In the Item Databound check if the current item is header then check the hedaer text for the column

if the headercolumn text is Publication ID then hide the column.

--anv
0
 

Author Comment

by:jmuldrum
ID: 17857522
Thanks for the quick answers.
hfpon:  This is the way I am currently doing the task, however I am interested
in automating this functionality so that I can drive it from the database
stored procedures a little more.

anv: I am able to use your technique, but there I was unable to get a
"HeaderText" property from the EventArg. Not that this was an issue,
but maybe I missed something ?

--jeff
0
 
LVL 5

Expert Comment

by:abith
ID: 20750421
use function of data grid to hide the auto generated columns called rowdatbound ()

code e.rows.item.cell(0).visible = false;

this way u can hide whatever column u want
0
 
LVL 1

Expert Comment

by:Hawkmoth
ID: 20866581
abith's idea worked for me
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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