如何动态加载相同的webusercontrol [英] how to load same webusercontrol dynamically
本文介绍了如何动态加载相同的webusercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个webusercontrol和一个面板,我想一个接一个地多次在面板中加载相同的用户控件。
i一直在追这个。
< pre lang =c#> UserControl uc = this .LoadControl( 〜/ uscEvents.ascx) as UserControl;
for ( int i = 0 ; i < 5 ; i ++)
{
panel.Controls.Add(uc);
}
但这只给我一个webusercontrol。如何获得许多?
解决方案
试试这样
< span class =code-keyword> for ( int i = 0 ; i < span class =code-keyword>< 5 ; i ++)
{
UserControl uc = this .LoadControl( 〜/ uscEvents.ascx)< span class =code-keyword> as UserControl;
pnl.Controls.Add(uc);
}
i have a webusercontrol and a panel, i want to load same user control in the panel multiple times one after the other.
i have been tying this.
UserControl uc = this.LoadControl("~/uscEvents.ascx") as UserControl;
for (int i = 0; i < 5; i++)
{
panel.Controls.Add(uc);
}
but this gives me only one webusercontrol. How to get many?
解决方案
Try like this
for (int i = 0; i < 5; i++) { UserControl uc = this.LoadControl("~/uscEvents.ascx") as UserControl; pnl.Controls.Add(uc); }
这篇关于如何动态加载相同的webusercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文