Re: dynamically loading usercontrol
- From: <param@xxxxxxxxxxxxxxxx>
- Date: Sun, 27 Jan 2008 11:47:54 -0600
Thank you.
"Milosz Skalecki [MCAD]" <mily242@xxxxxxxxxxxxxxxxx> wrote in message
news:2F210E41-74AA-4E21-96DF-9163DA88EE10@xxxxxxxxxxxxxxxx
Howdy,
Yes it is, two ways:
1. through data binding:
<asp:Repeater runat="server" ID="dynamicControls">
<ItemTemplate>
<uc1:MyUserControl runat="server" ID="userControl" CustomDateProperty='<%#
DateTime.Now %>'/>
</ItemTemplate>
</asp:Repeater>
2. or in the code behind:
<asp:Repeater runat="server" ID="dynamicControls"
OnItemDataBound="dynamicControls_ItemDataBound">
<ItemTemplate>
<uc1:MyUserControl runat="server" ID="userControl" />
</ItemTemplate>
</asp:Repeater>
-- c# code behind --
protected void dynamicControls_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if (item.ItemType == ListItemType.Item ||
item.ItemType == ListItemType.AlternatingItem)
{
MyUserControl ctrl = (MyUserControlClassName)
item.FindControl("userControl");
ctrl.CustomDateProperty = DateTime.Now;
}
}
HTH
--
Milosz
"param@xxxxxxxxxxxxxxxx" wrote:
OK,
Thanks for the tip. Now, what if I need to set custom properties on my
usercontrol. Is that possible?
TIA!
"Milosz Skalecki [MCAD]" <mily242@xxxxxxxxxxxxxxxxx> wrote in message
news:B89DDECD-A644-4935-AC3C-1501108EB518@xxxxxxxxxxxxxxxx
Howdy,
Use Repeater or DataList:
-- aspx code --
<asp:Repeater runat="server" ID="dynamicControls">
<ItemTemplate>
<uc1:myUserControl runat="server" ID="myUserControl"/>
</ItemTemplate>
</asp:Repeater>
-- c# code beside --
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int rowCount = 10;
myRepeater.DataSource = new int[rowCount];
myRepeater.DataBind();
}
}
Hope it helps
--
Milosz
"param@xxxxxxxxxxxxxxxx" wrote:
Hello all,
I have a UserControl that renders some HTML content. I now need to
dynamically load and render "n" instances of this usercontrol on a
host
aspx
page inside a panel control based upon user input of "n". Any ideas
how I
can do this?
TIA!
.
- References:
- dynamically loading usercontrol
- From: param
- Re: dynamically loading usercontrol
- From: param
- Re: dynamically loading usercontrol
- From: Milosz Skalecki [MCAD]
- dynamically loading usercontrol
- Prev by Date: Need help with Response.Redirect
- Next by Date: Re: Need help with Response.Redirect
- Previous by thread: Re: dynamically loading usercontrol
- Next by thread: Problem in setting Target Node and Target Tree Property
- Index(es):
Relevant Pages
|