Home > DeveloperSection > Forums > How to access dynamically created items in a repeater?
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    September-03-2014 11:19 PM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 897  View(s)
Rate this:

I have a repeater:

<asp:repeater id="someID" runat="server">

   <ItemTemplate>

      <asp:hyperlink id=<%# Eval("ID")%> runat="server"></asp:hyperlink>

   </ItemTemplate>

</asp:repeater>

I need to get reference to each hyperlink and access to the attributes of it.

On ItemDataBound, how do I go ahead and access a hyperlink whose ID is just being set? If I had a fixed ID for the hyperlink, that wouldn't be a problem. But since the I need the ID to also be assigned dynamically, I kinda got lost in finding the way.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-03-2014 11:42 PM

Hi Manoj, 

private void rptMyTest_ItemDataBound(object sender, RepeaterItemEventArgs e)

    {

        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)

        {

            Control control = e.Item.FindControl("ID_OF_YOUR_CONTROL") as Control;

            if (control != null)

            {

                var dataItem = e.Item.DataItem as MYITEMTYPE;

                if (DateTime.Now > dataItem.DateYouNeedToCheck)

                    control.ToolTip = "from the past";

              //ALL THE MAGIC HAPPENS HERE

            }

        }

    }


Don't want to miss updates? Please click the below button!

Follow MindStick