in my asp usercontrol I have a repeater and inside that some basic controls that do some databindng.
One of these controls holds an id
<asp:Repeater runat="server" ID="itemsRepeater" OnItemDataBound="itemsRepeater_ItemDataBound">
<ItemTemplate>
<asp:Label runat="server" ID="uId" Text='<%# DataBinder.Eval(Container.DataItem, "UserId") %>' />
<a href="myLink and @UserId" runat="server">
</ItemTemplate>
How can I grab my label uId and pass its associated id to @UserId for each element in the repeater.
I have nothing in my OnItemDataBound event yet, I am moving to it now to find a work around to this.
Thanks.
I fixed this by setting the databinder within the href
<a id="link" runat="server" href='<%# "Details.aspx?userId=" + DataBinder.Eval(Container.DataItem, "UserId") %>'>
A little modification in your code. I have just added a div around your Items.
<asp:Repeater runat="server" ID="itemsRepeater" >
<ItemTemplate>
<div>
<asp:Label id="uId" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "UserId") %>' /></asp:Label>
<a id="A1" runat="server">Click here</a>
</div>
</ItemTemplate>
</asp:Repeater>
Now your Js Code for adding uid to your link.
$(document).ready(function () {
var yourlink = 'myurl';
$('span[id^=itemsRepeater]').each(function (i) {
$(this).closest('div').find('a').prop('href', yourlink + $(this).html());
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.