c# - How do I add controls dynamically to a dynamically created panel? -
i have repeater creates n-number of panels. trying dynamically add different controls each of panels. may going wrong way.
my code more or less:
.aspx:
<asp:repeater id="repeater1" runat="server"> <itemtemplate> <% response.write("<asp:panel runat=\"server\" id=\"uxpanel_"); %> <%# databinder.eval(container.dataitem, "tableid")%><% response.write("\"></asp:panel>"); %> </itemtemplate> </asp:repeater>
.cs:
public partial class class1: system.web.ui.page { dataset ds= null; protected void page_load(object sender, eventargs e) { getrecords(1,1); } protected void getrecords() { ds= dal.loadrecords(); this.repeater1.datasource = ds.tables[0]; this.repeater1.databind(); literal lit = new literal(); lit.text = "some text"; this.findcontrol("uxpanel_1").controls.add(lit); }
}
just clear in example "dal.loadrecords" call method retrieves records db.
i think problem how adding panels in first place, seemed easy way have them uniquely named.
any pointers?
thanks
as previous answerer has said, fraught peril!
if must: should ditch repeater approach altogether.
create container panel or placeholder , in code behind dynamically add panels using containerpanel.controls.add(newpanel);
your child "panel" usercontrol if needs too.
be aware you'll have regenerate dynamic controls on postback.
Comments
Post a Comment