Solved

ASP.NET Datagrid show only selected columns from stored procedure

Posted on 2007-11-13
4
262 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

18 Experts available now in Live!

Get 1:1 Help Now