【问题标题】:Getting control ids in a repeater在中继器中获取控制 ID
【发布时间】:2012-07-11 13:59:17
【问题描述】:

我有以下 sn-p 在运行时在列表视图中获取控件 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>&nbsp
                </td>
            </tr>
        </ItemTemplate>
 </asp:ListView>

从 lbUnattend 生成 id 的链接按钮是我想要的。

有人指出问题出在哪里吗?

【问题讨论】:

  • 你在循环数据中的什么事件?

标签: c# asp.net .net repeater uniqueidentifier


【解决方案1】:

我认为你正在寻找的是

foreach (ListViewItem item in lvData.Items)
{
    Control ctrl = item.FindControl("lbUnattend");
    ctrl.Visible = false;
} 

【讨论】:

  • +1 您只能将FindControl 与服务器端ID(ID property)一起使用,而不是ClientID
猜你喜欢
  • 1970-01-01
  • 2019-02-10
  • 2012-03-23
  • 1970-01-01
  • 2021-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多