我有以下片段在运行时在列表视图中获取控件 ID。然而,尽管提供了正确的 id,但在调试时 ctrl 为空。
foreach (ListViewItem item in lvData.Items)
{
string uid = item.ClientID;
Control ctrl = lvData.FindControl(uid+"_lbUnattend");
ctrl.Visible = false;
}
我的模板:
<asp:ListView runat="server" ID="lvData" DataSourceID="odsEvents"
OnDataBound="lvData_DataBound"
onselectedindexchanged="lvData_SelectedIndexChanged">
<LayoutTemplate>
<table class="diary" cellspacing="0" width="600px">
<tr>
<th align="center">
Date:
</th>
<th align="center">
Time:
</th>
<th align="center">
Event:
</th>
<th align="center">
Location:
</th>
<th align="center">
</th>
</tr>
<tr runat="server" id="itemPlaceHolder">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td width="100px" align="center">
<%#FRT.Utils.DateTimeHelper.FormatToShortDate(Eval("StartDate"))%>
<%#FRT.Utils.DateTimeHelper.FormatToShortDate(Eval("VisitDateStart"))%>
</td>
<td width="100px" align="center">
<%#FRT.Utils.DateTimeHelper.FormatToShortTime(Eval("StartDate"))%>
<%#FRT.Utils.DateTimeHelper.FormatToShortTime(Eval("VisitDateStart"))%>
</td>
<td width="100px" align="center">
<%#Eval("Title")%>
</td>
<td width="200px" align="center">
<%# Eval("Address") %>
</td>
<td width="100px" align="center">
<asp:LinkButton ID="lbLogin" runat="server" Text="I want to attend this event" CssClass="button" />
<asp:LinkButton ID="lbAttend" runat="server" Text="I want to attend this event" CssClass="button" />
<asp:LinkButton ID="lbUnattend" runat="server" CommandName="unattend" Text="I want to unregister from this event" CssClass="button" />
<a href='<%# GetItemUrl(Eval("ActivityID"), Eval("SubEventID")) %>' class="button">See details</a> 
</td>
</tr>
</ItemTemplate>
</asp:ListView>
从 lbUnattend 生成的带有 id 的链接按钮是我想要的。
有人指出问题出在哪里吗?