Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在中继器中获取控制ID_C#_Asp.net_.net_Repeater_Uniqueidentifier - Fatal编程技术网

C# 在中继器中获取控制ID

C# 在中继器中获取控制ID,c#,asp.net,.net,repeater,uniqueidentifier,C#,Asp.net,.net,Repeater,Uniqueidentifier,我有以下代码段在运行时在listview中获取控件ID。但是,尽管提供了正确的id,但调试时ctrl为null foreach (ListViewItem item in lvData.Items) { string uid = item.ClientID; Control ctrl = lvData.FindControl(uid+"_lbUnattend"); ctrl.Visible = false; } 我的模板: <asp:ListView ru

我有以下代码段在运行时在listview中获取控件ID。但是,尽管提供了正确的id,但调试时ctrl为null

 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的链接按钮是我想要的


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

我想你要找的是

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

您在数据中循环执行什么事件?+1您只能使用服务器端ID的
FindControl
,而不能使用
ClientID