lundi 19 juin 2017

Get Checkbox Object from a Repeater

I have a repeater and I am trying to access the Checkbox controller from the LinkButton event.The Repeater controls only contain the literals and linkbuttons but not checkbox controls.

<asp:Repeater ID="rptTicketsInPerformance" OnItemDataBound="rptTicketsInPerformance_ItemBound" runat="server">
 <ItemTemplate>
   <asp:CheckBox ID="cbticketSelect" runat="server" />
   <asp:Literal ID="ltticketDescription" runat="server" />
 </ItemTemplate>
 <FooterTemplate>
   <div class="change-buttons">
   <asp:LinkButton ID="btDonate" runat="server" CssClass="button-primary" Text="Donate"  OnClick="donateButton_click" />
   <asp:HyperLink ID="hlCancel" runat="server" CssClass="button-primary close-reveal-modal" Text="Cancel" />
   </div>
 </FooterTemplate>
</asp:Repeater>

Code Behind

    protected void donateButton_click(object sender, System.EventArgs e)
    {
        RepeaterItem items = ((sender as LinkButton).Parent as RepeaterItem);
        foreach(var itm in items.Controls)
        {
            if(itm is CheckBox)
            {
              // Do something here
            }
        }
     }




Aucun commentaire:

Enregistrer un commentaire