[英]ASP.NET GridView set values using JavaScript Fucntion
In the ItemTemplate of TemplateField of the GridView itis posible to set value using functions from CodeBehind. 在GridView的TemplateField的ItemTemplate中,可以使用CodeBehind中的函数设置值。 In the example I call getImgUrl and getNavUrl to set Image and Navigate URLs.
在示例中,我调用getImgUrl和getNavUrl设置图像和导航URL。 I would like to know the syntax required to call a JavaScript function instead of a code behind function.
我想知道调用JavaScript函数而不是函数背后的代码所需的语法。 That is, the combination of brackets, percent signs, hashtags, etc.
也就是说,方括号,百分号,#标签等的组合。
<asp:HyperLink ID="hHoldEm" Target="_parent" runat="server" Font-Underline="false" ImageUrl='<%# getImgUrl(Eval("CER_ACTIVE"))%>' ToolTip="Hold/UnHold..." ImageWidth="20" NavigateUrl='<%# getNavUrl(Eval("CER_ACTIVE"), Eval("CER_NO"))%>'/>
You cannot call a function in code behind with a HyperLink
by adding a OnClick
event as you would a Button
. 您不能像添加
Button
那样通过添加OnClick
事件来在HyperLink
后面的代码中调用函数。
But you can call javascript function in an anchor like this 但是您可以像这样在锚中调用javascript函数
<a href="javascript:myFunction()">Click for JavaScript</a>
So to do the same in the GridView you can do this 因此,在GridView中执行相同操作即可
<asp:HyperLink ID="hHoldEm" runat="server" NavigateUrl='<%# "javascript:" + getNavUrl(Eval("CER_ACTIVE"), Eval("CER_NO")) %>' />
or 要么
<asp:HyperLink ID="hHoldEm" runat="server" NavigateUrl='<%# "javascript:myFunction('" + Eval("CER_ACTIVE") + "', '" + Eval("CER_NO") + "')" %>' />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.