Solved

ASP.NET Datagrid show only selected columns from stored procedure

Posted on 2007-11-13
4
260 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks guys, AlexCode got in there first, but thank you both very much
0

Featured Post

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.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

12 Experts available now in Live!

Get 1:1 Help Now