href javascript 链接中的数据绑定值

Databound Value in href javascript link

本文关键字:数据绑定 javascript 链接 href      更新时间:2023-09-26

我已经在网上寻找语法来使其工作,我希望这是一个快速解决方案,否则我会发疯。 基本上我有一个嵌套中继器,下面的按钮隐藏了另一个嵌套中继器。

((location_details)((RepeaterItem)Container.Parent.Parent).DataItem).tbl_location.location_id评估非常好(在我测试的情况下为 3824),但是当我尝试传递它以便它是 javascript 函数的字符串参数时,它每次都会失败。

<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;' />

缺少的任何想法(我知道上面的语法是错误的,我一定已经更改了 100 次,但你明白了)。

谢谢!

你试过asp:HyperLinkNavigateUrl吗?我认为asp:LinkButton渲染到锚标签及其href属性应该由ASP生成(因此会导致回发),这就是它不会绑定到它的原因。

我现在无法对此进行测试,因此这可能是错误的,但是您不需要将href的值连接在一起。

<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;' />