Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set DataSource on controls within a UserControl?
Message
 
To
15/04/2009 13:59:01
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01395026
Message ID:
01395038
Views:
50
>I have created my first asp.net UserControl that I will use in several places throughout my app. It contains a FormView to display fields of the record in a DataTable.
>
>It all seems fine, except, I can't figure out how to set the DataSource on the FormView that is within the UserControl. I want to set the DataSource in a method in code-behind.
>
>I see from intellisense that the UserControl does not have a DataSource property, but it does have a DataBind method. I can imagine that one might need to set different DataSources on multiple controls within a UserControl, so there must be some method for drilling into a UserControl, but I cannot figure it out.
>
>Since UT will not let me post aspx code (it always gives an error when I try to post asp.net code), please see the code at this link on StackOverflow:
>
>http://stackoverflow.com/questions/752935/set-datasource-on-controls-within-asp-net-usercontrol
>-

You can just expose a property on the UserControl that sets this for you.
public string DataSource
{
   get { return this.FormViewName.DataSource; }
   set { this.FormViewName.DataSource = value; }
}
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Reply
Map
View

Click here to load this message in the networking platform