Solved

Dynamic Gridview - binding more than one column from an objectdatasource

Posted on 2006-11-07
1
325 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
ID: 17888942
Set autogeneratecolumns to true...

GridView1.AutoGenerateColumns = True

and drop all the other code.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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