我有一个中继器,如下所示。如何在后面的代码中获取报告 ID(从 hiddenContent2 中的表达式)?
表达式是
<%# Eval("ReportID") %>
注意:我更喜欢不使用“FindControl”的方法。
ASP.NET
<asp:Repeater ID="rptReports" runat="server">
<HeaderTemplate>
<div></div>
</HeaderTemplate>
<ItemTemplate>
<div id="repeaterIdentifier" class="repeaterIdentifier">
<div id="reportTitle" class="reportTitle">
<%# Eval("Title") +":" %>
</div>
<div id ="reportFrequency" class="reportFrequency">
<%# " Frequency - "+ Eval("Frequeny") %>
</div>
</div>
<div class="reportContent">
<div class="repeaterLine">
<asp:TextBox ID="txtEmailRecipients" runat="server" class="textEdit" Text='<%# Eval("Recipients")%>' TextMode="MultiLine"></asp:TextBox>
</div>
</div>
<div id="hiddenContent2">
<%# Eval("ReportID") %>
</div>
</ItemTemplate>
</asp:Repeater>
代码背后
protected void Save_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in rptReports.Items)
{
foreach(Control c in item.Controls)
{
string test1 = c.ID;
Type t = c.GetType();
}
string emails = ((TextBox)item.Controls[1]).Text;
}
}