Search code examples
asp.netrepeaterfindcontrolasprepeater

Reaching repeater item: The Logic


Here is my design page:

<asp:MultiView ID="mvProducts" runat="server" ActiveViewIndex="0">
  <asp:View runat="server" ID="mvProducts1">
    <asp:Repeater ID="rptDiscount" runat="server">
      <ItemTemplate>
        <div class="divProduct1">
          <div class="divProductHeader">
            <asp:Panel ID="pnlDiscount" runat="server" CssClass="divProductHeaderDiscount" Visible="true">
              <div class="menuTextTopSpacer"></div>
              <asp:Label ID="lblDiscount" runat="server" Text='<%#Eval("discount") %>'></asp:Label>
            </asp:Panel>`

I just want to reach pnlDiscount item but I dont know how. I made a search but it just helped to increase my confusion.

Indeed, I want to learn the logic on finding a control in a repeater.


Solution

  • Use ItemDataBound on your reapter then use FindContol() to get to the Panel

    protected void rptDiscount_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Panel myPanel= e.Item.FindControl("pnlDiscount") as Panel;
    
        //Do some work
    }