?
Solved

ASP.NET Datagrid show only selected columns from stored procedure

Posted on 2007-11-13
4
Medium Priority
?
271 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 1200 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 Ageil
Sammy Ageil earned 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

840 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