Solved

ASP.NET Datagrid show only selected columns from stored procedure

Posted on 2007-11-13
4
261 Views
Last Modified: 2012-08-13
Hi Experts.

Im still Brand new at ASP.NET

I have created a datagrid from an sql database.

<asp:DataGrid AutoGenerateColumns="true" Width="550px" AlternatingItemStyle-BackColor="Gainsboro"  CellPadding="3" DataSource="<%# Get_Students1.DefaultView %>" Enabled="true" ID="Grid1" runat="server" ShowFooter="false" ShowHeader="false" gridline="Both"></asp:DataGrid>

It comes out real good.

The question is, how do I only show the columns that I want from the stored procedure.

I have say column a,b,c,d,e,f and I only want to show b,c and d in the datagrid.

How do I get just those columns out?

Cheers
0
Comment
Question by:nikdonovanau
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 300 total points
ID: 20277784
set AutoGenerateColumns="false"

and then add columns like:

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:checkboxfield DataField="Column1Flag" HeaderText="MyFlag1">
                </asp:checkboxfield>
            </Columns>
        </asp:GridView>
0
 
LVL 27

Assisted Solution

by:Sammy
Sammy earned 200 total points
ID: 20277785
if you set AutoGenerateColumns="false" and add the columns in your aspx file
<Columns>
                <asp:BoundField DataField="ColumnNameHere" HeaderText="HeaderTextHere"
                   SortExpression="ColumnNameHere" />
                <asp:BoundField DataField="ColumnNameHere" HeaderText="HeaderHere" SortExpression="ColumnNameHere" />
            </Columns>
that will display the selected columns only
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20277792
If you don't like adding columns directly on code you can use the grid designer.

At the designer, on the top right corner of the grid you'll find the "Common GridView Tasks" where you have the "Edit Columns..."
0
 
LVL 1

Author Comment

by:nikdonovanau
ID: 20277826
Thanks guys, AlexCode got in there first, but thank you both very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

23 Experts available now in Live!

Get 1:1 Help Now