Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET Datagrid show only selected columns from stored procedure

Posted on 2007-11-13
4
Medium Priority
?
268 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
[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
  • 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

Independent Software Vendors: 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

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…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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