datalist eval传递给javascript而不是workig

时间:2017-08-20 07:53:33

标签: javascript asp.net datalist

我将eval值从datalist传递给javascript函数,但它没有传递。 "&将First_Name#34;没有通过,但是当我通过" Job_Id"参数然后它成功显示值。我怎样才能通过" First_Name"。以下是我的代码:



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>jQuery UI Autocomplete - Multiple values</title>
    
    <script type="text/javascript">
        function ShowModalPopup(name) {
            alert(name);
            return false;         
        }       
    </script>
</head>
<body style="margin: 0px 0px 0px 0px;">
    <form id="form1" runat="server">
   
    <div style="width: 100%;">
        <asp:DataList ID="dlJobs" runat="server" RepeatDirection="Horizontal" RepeatColumns="1"
            DataKeyField="Job_Id" CellPadding="10" ItemStyle-VerticalAlign="Top" Width="100%"
            OnItemCommand="dlJobs_ItemCommand">
            <ItemTemplate>
                <div style="font-size: small; float: right; margin-left: 20px;">
                    <asp:LinkButton ID="lnkContactReferrer" Text="Contact Referrer" runat="server" CommandArgument='<%# Eval("Job_Id") %>'
                        CommandName="ContactReferrer" Style="background: #4E9CAF; padding: 5px 10px 5px 10px;
                        text-align: center; border-radius: 5px; color: white; font-weight: bold; text-decoration: none;
                        margin-left: 5px; margin-right: 5px;" OnClick='<%# "return ShowModalPopup(" +Eval("First_Name") + " );" %>'></asp:LinkButton>
                </div>
            </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>
&#13;
&#13;
&#13;

请咨询

1 个答案:

答案 0 :(得分:0)

名称是字符串值。您必须添加双引号以调用ShowModalPopup方法,如下所示。

ShowModalPopup("Jon")

您的代码中缺少双引号。

OnClick='<%# "return ShowModalPopup(\"" + Eval("First_Name") + "\");" %>'