Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2006, 05:19 PM
Authorized User
 
Join Date: Dec 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing a DataSource to a user control

Is it possible to have a generic user control (productListing.ascx) that contains only a GridView and no ObjectDataSource linked to it?

What we want is to dynamically set the ObjectDataSource instead of statically declaring it in the .ascx file.

For example, in the Search.aspx page:

Code:
Search Results:
<uc1:ProductListing ID="pl" runat="server" />
We want to, somehow, pass the DataSource (List<Product>) to the productListing at this level.

So we can have another page, Highlights.aspx:

Code:
<h2>Our 10 best sellers:</h2>
<uc1:ProductListing ID="pl" runat="server" />

<h2>Check out the latest articles:</h2>
<uc1:ArticleListing ID="al" runat="server" />
The ObjectDataSource of both cases do not come from the same place.

 
Old January 8th, 2007, 11:04 AM
Authorized User
 
Join Date: Dec 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

(I know I'm replying to my own question)

Yes, it is possible. In the code-behind file, do something like this:

Code:
GridView gridView = ((GridView)produitListing.FindControl("gridView"));
gridView.DataSource = myDataSource;
gridView.DataBind();





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing parameters to user control jbeynon ASP.NET 2.0 Professional 0 August 30th, 2006 06:18 AM
Passing as object as a Param to a Web User Control MixedCode General .NET 2 December 8th, 2004 11:36 AM
Passing datasource to a stored procedure ctranjith SQL Server 2000 2 October 7th, 2004 01:49 PM
Passing a Value to a User Control DC Ross ASP.NET 1.0 and 1.1 Basics 2 February 17th, 2004 06:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.