简体   繁体   中英

Databound Value in href javascript link

I've trawled the net looking for the syntax to get this working and i'm hoping this is a quick fix else i'll go mad. Basically I have a nested repeater and the button below hides another nested repeater.

((location_details)((RepeaterItem)Container.Parent.Parent).DataItem).tbl_location.location_id evaluates perfectly well (3824 in the case i'm testing), but when I try to pass it so that its a string parameter for the javascript function it fails everytime.

<asp:Linkbutton ID="lb_showhide_oloc_gnotes" runat="server" Text="Expand/Close" 
 href='javascript:sltoggle('" + <%# ((location_details)((RepeaterItem)Container.Parent.Parent).DataItem).tbl_location.location_id %> +" '); return false;' />

Any ideas what i'm missing (I know the above syntax is wrong I must have changed it 100 times already but you get the idea).

thanks!

I can't test this right now so this might be wrong, but you don't need to concatenate the value of href together.

<asp:Linkbutton ID="lb_showhide_oloc_gnotes" runat="server" Text="Expand/Close" 
 href='javascript:sltoggle("<%# ((location_details)((RepeaterItem)Container.Parent.Parent).DataItem).tbl_location.location_id %>"); return false;' />

Have you tried asp:HyperLink and NavigateUrl ? I think asp:LinkButton renders to an anchor tag and its href attribute should be generated by ASP (so it results in a postback) and that's why it won't bind to it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM