Search code examples
jqueryhtmlasp.netwebformsrepeater

Appending parent elements attribute to the URL of anchor tag href


<asp:Repeater runat="server" ID="rptStockListings">
  <ItemTemplate> 
    <li rank=<%#GetRank(DataBinder.Eval(Container.DataItem,"r"))
       ...............
       <a href="<%# DataBinder.Eval(Container.DataItem,"Url")

I have URL already but i want to append the rank attribute of li element which is ancestor of this anchor with href="Url".

How can I do that?

Basically i want to pass information to the next opened page by anchor tag in the url itself.


Solution

  • Hope this helps

    <a onclick='openThis(<%# DataBinder.Eval(Container.DataItem,"Url"), this)'>Click here</a>
    

    In javascript:

    function openThis(url, obj) {
        var appendThis = $(this).closest("li").attr("rank");
        window.open(url+appendThis + , "_self")
    }