Click here to Skip to main content
15,886,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


Am using repetor for anchor tag,whenever i bind the data to the repeator the anchor tag id is same for all created anchor tags in repeator because of that i failed to call the script how to solve these issue
Posted

Append the unique Id using Eval.

C#
<a id="a_<%# Random() %><%# DataBinder.Eval(Container,"itemindex") %>" />
C#



Random()is a function in your code behind which returns a random number
 
Share this answer
 
v2
Comments
Member 10226004 30-May-14 5:41am    
i need to genarate id for anchor tags in repeator as a1,a2,a2.............how can i do this if it is in repeator
The individual anchor tags in the repeater will be given unique ids. check this out:
aspx page:
XML
<head runat="server">
    <script>
        function myfunction(obj) {
            alert(obj.id);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <div style="font-weight: bold;">
                    Repeater Demo</div>
            </HeaderTemplate>
            <ItemTemplate>
                <div>
                    <a href='<%# Container.DataItem %>' runat="server" onclick="myfunction(this);" id="mylink">
                        <%# Container.DataItem %></a>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>

code behind:
XML
protected void Page_Load(object sender, EventArgs e)
{
    List<string> myList = new List<string>();
    myList.Add("Link1");
    myList.Add("Link2");
    myList.Add("Link3");

    Repeater1.DataSource = myList;

    Repeater1.DataBind();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900