Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Databinding a Web UserControl

Reply
Thread Tools

Databinding a Web UserControl

 
 
Allan Ebdrup
Guest
Posts: n/a
 
      05-19-2006
I have a Web User Control (.ascx page) wherin i have a repeater, now I would
like to databind to the Web User Control, and have it databind to the
repeater in the control. Ive taken a look at the walkthroughs at:
http://msdn2.microsoft.com/en-us/library/ms233813.aspx
http://msdn2.microsoft.com/en-us/library/ms171926.aspx

but can't really see what would be the best solution for this kind of nested
databinding, I mean what If I have several repeaters in my Web User Control
that I want to databind seperately, what would be the best practice for
implementing this kind of nested databinding?

It is important that I encapsulate the databinding in my Web User Control so
that I can replace it with another Web User Control that has the same
databinding behaviour, and that way make several Web User Controls that I
can switch on the main page seamlessly without having to modify anything on
the main page other than use a different Web User Control.

Any Ideas?

Kind Regards,
Allan Ebdrup


 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      05-22-2006
Hi Allan,

Thank you for posting!

For Complex Data Binding, the attribute ComplexBindingProperitesAttribute
can only be used to specify one DataSource/DataMember. But this attribute
is only required by Designer, not mandatory for implementing data binding
user controls.

Based on my understanding, we can here simply expose those Repeaters'
DataSource property individually. For example:

==========
Create a Web User Control and add two repeaters:

public partial class WebUserControl : System.Web.UI.UserControl
{
public object DataSource1
{
get { return Repeater1.DataSource; }
set { Repeater1.DataSource = value; }
}

public object DataSource2
{
get { return Repeater2.DataSource; }
set { Repeater2.DataSource = value; }
}
}

==========
When using this user control, specify two data sources by code, then call
DataBind:

WebUserControl1.DataSource1 = ds1;
WebUserControl1.DataSource2 = ds2;
WebUserControl1.DataBind();

==========

Hope this helps.



Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
Allan Ebdrup
Guest
Posts: n/a
 
      05-22-2006
"Walter Wang [MSFT]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> For Complex Data Binding, the attribute ComplexBindingProperitesAttribute
> can only be used to specify one DataSource/DataMember. But this attribute
> is only required by Designer, not mandatory for implementing data binding
> user controls.
>
> Based on my understanding, we can here simply expose those Repeaters'
> DataSource property individually. For example:
>
> ==========
> Create a Web User Control and add two repeaters:
>
> public partial class WebUserControl : System.Web.UI.UserControl
> {
> public object DataSource1
> {
> get { return Repeater1.DataSource; }
> set { Repeater1.DataSource = value; }
> }
>
> public object DataSource2
> {
> get { return Repeater2.DataSource; }
> set { Repeater2.DataSource = value; }
> }
> }
>
> ==========
> When using this user control, specify two data sources by code, then call
> DataBind:
>
> WebUserControl1.DataSource1 = ds1;
> WebUserControl1.DataSource2 = ds2;
> WebUserControl1.DataBind();
>


Yes that did the trick.
I also had to define a interface that both Web User Controls implement and
use Page.FindControl to find the swapped control and cast it to the
interface.
But now it works, I can programatically switch a Web User Control on the
page with another.

Thanks,
Allan Ebdrup


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all? Sergei Shelukhin ASP .Net 1 11-12-2006 01:43 PM
web usercontrol + delegates or specialised usercontrol base class info@record-play.com ASP .Net 0 06-23-2006 09:41 AM
Web Usercontrol in a Web Usercontrol not displaying... Kan Grewal ASP .Net Web Controls 2 07-07-2004 08:12 AM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM



Advertisments