通過Eval將多個參數傳遞給Javascript函數

[英]Pass multiple arguments through Eval to Javascript function


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>

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/06/17/375e3421803d2f9303f756e044706085.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com