Solved

Dynamic Gridview - binding more than one column from an objectdatasource

Posted on 2006-11-07
1
318 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 500 total points
Comment Utility
Set autogeneratecolumns to true...

GridView1.AutoGenerateColumns = True

and drop all the other code.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall‚Ķ
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

15 Experts available now in Live!

Get 1:1 Help Now