Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamic Gridview - binding more than one column from an objectdatasource

Posted on 2006-11-07
1
Medium Priority
?
342 Views
Last Modified: 2008-01-09
I have a gridview (Gridview1) defined as follows:-

<asp: GridView ID="Gridview1" runat = "server" AutoGenerateColumns="false" DataSourceID="ObjectDataSource1">
<Columns>
</Columns>
</asp:Gridview>

and columns dynamically added using

private void BuildGridView()
{
BoundField column1 = new BoundField();
column1.DataField = "ID";
column1.HeaderText = "ID"
GridView1.Columns.Add(column1);

BoundField column2 = new BoundField();
column2.DataField = "FirstName";
column2.HeaderText = "FirstName"
GridView1.Columns.Add(column2);

}
 
How do I "tidy up" this code (using eg "foreach") so I do not have to specify each individual column in the objectdatasouce.

 (ie how do I automatically bind all the columns in the objectdatasource?)

Thanks !
0
Comment
Question by:doolinn
1 Comment
 
LVL 11

Accepted Solution

by:
ethoths earned 1000 total points
ID: 17888942
Set autogeneratecolumns to true...

GridView1.AutoGenerateColumns = True

and drop all the other code.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Loops Section Overview
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

972 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