Solved

Dynamic Gridview - binding more than one column from an objectdatasource

Posted on 2006-11-07
1
336 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
[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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

635 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