[英]How can I reference a repeater inside a usercontrol inside a webpart
Noobie, question, I dont remember ! Noobie,问题,我不记得了!
I created a visual webpart, which creates a user control, I added a repeater in htnml view, and now I need to bind it to data, however I cant seem to find the repeater control in the codebehind. 我创建了一个可视化Web部件,它创建了一个用户控件,在htnml视图中添加了一个转发器,现在我需要将其绑定到数据,但是我似乎无法在后面的代码中找到转发器控件。
<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 my webpart 还有我的webpart
public class EngagementLetterWebPart : WebPart
{
// Visual Studio might automatically update this path when you change the 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 the repeater using following steps 您可以使用以下步骤绑定转发器
1.Declare a public variable 1,声明一个公共变量
Control innerControl;
2.Change the createchildcontrols function as below 2,更改createchildcontrols函数如下
protected override void CreateChildControls()
{
innerControl = Page.LoadControl(_ascxPath);
Controls.Add(innerControl);
}
3.Change the BindData function as below 3,按如下所示更改BindData函数
private void BindData()
{
if (innerControl != null)
{
//here, how??
Repeater repeater = innerControl.FindControl("repeater") as Repeater;
if (repeater != null)
{
repeater.DataSource = JobContext.GetEngagementLetterReport(SPContext.Current.Site, true, 500, 1);
repeater.DataBind();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.