c# - How can I reference a repeater inside a usercontrol inside a webpart -
noobie, question, dont remember !
i created visual webpart, creates user control, added repeater in htnml view, , need bind data, cant seem find repeater control in codebehind.
<table id="engagementletterreport" class="display" border="0"> <thead> <tr> <th>jobcode</th> <th>jobname</th> </tr> </thead> <tbody> <asp:repeater runat="server" id="repeater"> <itemtemplate> <tr> <td> <%# databinder.eval(container.dataitem, "jobcode") %> </td> <td> <%# databinder.eval(container.dataitem, "jobname") %> </td> </tr> </itemtemplate> </asp:repeater> </tbody> </table>
and webpart
public class engagementletterwebpart : webpart { // visual studio might automatically update path when change visual web part project item. private const string _ascxpath = @"~/_controltemplates/15/xx.sp.xx.webparts.webparts/engagementletterwebpart/engagementletterwebpartusercontrol.ascx"; protected override void createchildcontrols() { control control = page.loadcontrol(_ascxpath); controls.add(control); } protected override void onload(eventargs e) { binddata(); } private void binddata() { //here, how?? repeater.datasource = jobcontext.getengagementletterreport(spcontext.current.site, true, 500, 1); repeater.databind(); } }
you can bind repeater using following steps
1.declare public variable
control innercontrol;
2.change createchildcontrols function below
protected override void createchildcontrols() { innercontrol = page.loadcontrol(_ascxpath); controls.add(innercontrol); }
3.change binddata function below
private void binddata() { if (innercontrol != null) { //here, how?? repeater repeater = innercontrol.findcontrol("repeater") repeater; if (repeater != null) { repeater.datasource = jobcontext.getengagementletterreport(spcontext.current.site, true, 500, 1); repeater.databind(); } } }
Comments
Post a Comment