通过Eval将多个参数传递给Javascript函数

时间:2022-05-20 16:02:26

I am trying very hard to pass three parameters to a javascript function from within a itemtemplate of a gridview:

我正在努力将三个参数从gridview的itemtemplate中传递给javascript函数:

For one parameter, it works fine:

对于一个参数,它工作正常:

<asp:HyperLink ID="hypComment" runat="server" Font-Bold="True"
NavigateUrl='<%# Eval("CCN", "javascript:ShowCommentPopUp({0});") %>'>Add
</asp:HyperLink>

where CCN is my column in gridview. This will actually pass the ccn in which the row is clicked:

其中CCN是gridview中的专栏。这实际上将传递单击该行的ccn:

I want to pass two more params: "Name" and "Status" are the corresponding columns as the 2nd and 3rd arguments for the ShowCommentPopUp function. I tried many ways, but ended up in all syntax errors. Lot of time is invested.

我想再传递两个参数:“Name”和“Status”是相应的列,作为ShowCommentPopUp函数的第2和第3个参数。我尝试了很多方法,但最终出现了所有语法错误。投入了大量时间。

for example:

NavigateUrl='<%# Eval(["CCN", "NAME", "javascript:ShowCommentPopUp({0}, {1});")

etc etc

if anyone can help me, it is greatly appreciated.

如果有人能帮助我,我们非常感谢。

thanks, Aparna

3 个解决方案

#1


Do you mean NavigateUrl='<%# Eval(["CCN", "NAME"], "javascript:ShowCommentPopUp({0}, {1});")?

你的意思是NavigateUrl ='<%#Eval([“CCN”,“NAME”],“javascript:ShowCommentPopUp({0},{1});”)?

#2


Using this code you can solve your problem:

使用此代码可以解决您的问题:

<asp:HyperLink ID="hypComment" runat="server" Font-Bold="True" NavigateUrl="#" OnClick="<%# String.Format("javascript:return ShowCommentPopup(""{0}"",""{1}"")",Eval("CCN"),Eval("parametername"))  %>">
    Add
</asp:HyperLink>

#3


I had the same problem and lots of problems to get it to work.

我有同样的问题和很多问题让它工作。

Eventually this worked for me: you have to place the resulting values of the eval functions between quotes. And these quotes must be html save, so replace the ' character into '

最终这对我有用:你必须将eval函数的结果值放在引号之间。这些引号必须是html save,所以将'character into'替换

For me at least, only then my dialog, containing the three parameters showed.

至少对我来说,只有我的对话框,包含三个参数显示。

<ItemTemplate>
   <asp:Button ID="btnEdit" CssClass="btnmaatwerksmall" runat="server" Text="Wijzig"
       OnClientClick='<%# String.Format("OpenChildNietInEnterprise(&apos;{0}&apos;,&apos;{1}&apos;,&apos;{2}&apos;);", Eval("CursusNaam"), Eval("VerwachteOmzetJaar"), Eval("VerwachteOmzetKomendeJaren")) %>' />
 </ItemTemplate>

#1


Do you mean NavigateUrl='<%# Eval(["CCN", "NAME"], "javascript:ShowCommentPopUp({0}, {1});")?

你的意思是NavigateUrl ='<%#Eval([“CCN”,“NAME”],“javascript:ShowCommentPopUp({0},{1});”)?

#2


Using this code you can solve your problem:

使用此代码可以解决您的问题:

<asp:HyperLink ID="hypComment" runat="server" Font-Bold="True" NavigateUrl="#" OnClick="<%# String.Format("javascript:return ShowCommentPopup(""{0}"",""{1}"")",Eval("CCN"),Eval("parametername"))  %>">
    Add
</asp:HyperLink>

#3


I had the same problem and lots of problems to get it to work.

我有同样的问题和很多问题让它工作。

Eventually this worked for me: you have to place the resulting values of the eval functions between quotes. And these quotes must be html save, so replace the ' character into '

最终这对我有用:你必须将eval函数的结果值放在引号之间。这些引号必须是html save,所以将'character into'替换

For me at least, only then my dialog, containing the three parameters showed.

至少对我来说,只有我的对话框,包含三个参数显示。

<ItemTemplate>
   <asp:Button ID="btnEdit" CssClass="btnmaatwerksmall" runat="server" Text="Wijzig"
       OnClientClick='<%# String.Format("OpenChildNietInEnterprise(&apos;{0}&apos;,&apos;{1}&apos;,&apos;{2}&apos;);", Eval("CursusNaam"), Eval("VerwachteOmzetJaar"), Eval("VerwachteOmzetKomendeJaren")) %>' />
 </ItemTemplate>