【发布时间】:2015-07-24 12:50:41
【问题描述】:
我是asp.net 的初学者,这是我第一次遇到asp 中继器。 它是 .ascx 页面中的中继器控件,我想绑定到 C# 代码
在 .ascx 页面中:
<asp:Repeater ID="relatedFilesRepeater" runat="server" OnItemDataBound="RelatedFilesRepeater_ItemDataBound">
<ItemTemplate>
<tr>
<td width="30%">
<asp:Label ID="fileNameLabel" runat="server" />
</td>
<td>
<asp:ImageButton ID="signatureButton" runat="server" ImageUrl="~/Images/Icons/16x16/_Base Image/Symbol Check 2.png" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
在我的 .ascx 页面顶部,我已经在 C# 中声明了我的 OnItemDatabound 函数,如下所示:
<script language="C#" runat="server">
void RelatedFilesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
...
}
而且效果很好。但是将 c# 代码留在 .ascx 中既不美观也不干净
如何将我的OnItemDataBound 函数放在我的代码后面并将其与asp 转发器绑定。因为我试图简单地将我的 c# 代码复制粘贴到文件后面的代码中,但它不起作用。
【问题讨论】:
-
“不工作”是什么意思?
-
可以将此功能移动到cs文件,执行此操作并解释什么不起作用并显示.ascx文件的标题
-
我的 .ascx 页面中使用了一些标签,例如 fileNameLabel 和 fileName,但它们在我的代码隐藏页面中无法识别。所以编译时会出错。
-
您无法直接访问这些标签。原因是它们被包裹在中继器中,因此首先您必须找到正确的中继器行,然后使用 row.findcontrol 并提供 ctrl id。
-
好的。但您没有提到该行表示 ctrl 的父级。
标签: c# asp.net asprepeater