Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Dynamically calling user controls

  Asked By: Leon    Date: Feb 02    Category: Asp.net    Views: 957
  

I have a datagrid bound to a table. In the table I have a text field
that contains the name of a user control. My intent is to
dynamically load a series of user controls in an aspx file driven by
the names stored in this table.

Essentially, I want the datagrid to load the appropriate user control
for each record in my table.

Assume that I have <%@ Register %> declarations for each of the
possible 10 user controls that I may call. How do I get the datagrid
to dynamically load the corresponding user control with the
<ItemTemplate> tag?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Huette Miller     Answered On: Feb 02

All I can suggest is that you look into a nesetd repeater (search at google.com).

Can I also suggest you hava look at the GotDotNETMenuSorce available at www.gotdotnet.com

This latter will show you how to add repeaters(or controls) in a loop. It is NOT a nested repeater, but you can so some stuff with it in the meantime. It will teach you how to use FindControl and its possible drawbacks.

Basically .... you need to control  your aspx  page from the code behind, adding the controls  by code.

You names  of your controls as would come from your database I shall refer to as CName1,2,3,4,5, and the code would be something like

sya db dished out dataset and refer to it as dr["controlname"]


FillPage(){

if (dr["controlname") = CName1 {
Control1 c1 = new Control1();
c1 = (Control1)LoadControl("sunfolder/control1.ascx");
this.Controls.Add(menuSection);
}
if (dr["controlname") = CName1 {
Control1 c1 = new Control1();
c1 = (Control1)LoadControl("sunfolder/control1.ascx");
this.Controls.Add(menuSection);
}
if (dr["controlname") = CName1 {
Control1 c1 = new Control1();
c1 = (Control1)LoadControl("sunfolder/control1.ascx");
this.Controls.Add(menuSection);
}
}

}

 
Didn't find what you were looking for? Find more on Dynamically calling user controls Or get search suggestion and latest updates.




Tagged: