I'm trying to loop through all the webusercontrols i have in a database and add them to a placeholder in a repeater if they exist. I can work it out, but the thing I can't work out is that I usually load a control in to a place holder like:
WebHosting ctrlWebhosting = (WebHosting)Page.LoadControl("~/Controls/" + nRow["ClientServiceList"]);
However, how do I cast to a WebHosting for example if from an item from teh database.
I thought about something like the following but it doesn't work:
DataRowView nRow = null;
switch (e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
nRow = (DataRowView)e.Item.DataItem;
Panel PlaceHolder1 = (Panel)e.Item.FindControl("phService");
nRow["ClientServiceList"] ctrlWebhosting = (nRow["ClientServiceList"])Page.LoadControl("~/Controls/" + nRow["ClientServiceList"]);
ctrlWebhosting.CompanyID = Session["CompanyID"].ToString();
PlaceHolder1.Controls.Add(ctrlWebhosting);
break;
}
The front of the repeater is:
<asp:Repeater runat="server" ID="rptServices" OnItemDataBound="rptServices_ItemDataBound">
<itemtemplate>
<asp:PlaceHolder runat="server" ID="phService"></asp:PlaceHolder>
</itemtemplate>
</asp:Repeater>