tracer tong
tracer tong

Reputation: 553

Getting control ids in a repeater

I have the following snippet getting control ids in a listview at runtime. However ctrl is null when debugged in spite of the correct id being provided.

 foreach (ListViewItem item in lvData.Items)
 {
    string uid = item.ClientID;
    Control ctrl = lvData.FindControl(uid+"_lbUnattend");
    ctrl.Visible = false;
 }

my template:

 <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>

where linkbuttons whith ids generated from lbUnattend are the ones I want.

Anyone pointout where the problem is?

Upvotes: 0

Views: 132

Answers (1)

Rawling
Rawling

Reputation: 50114

I think what you're looking for is

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

Upvotes: 2

Related Questions