简体   繁体   中英

How to get list box item reference in javascript function

I have Listview control on webform.aspx page with below defination...

<asp:ListView runat="server" ID="dispalyProducts">
            <LayoutTemplate>
                <table runat="server" id="table1">
                    <tr runat="server" id="itemPlaceholder">
                    </tr>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr id="Tr1" runat="server">
                    <td id="Td1" runat="server">
                        <%-- Data-bound content. --%>
                        <asp:Label runat="server" Text='<%#Eval("ProductName") %>' />
<br/>
                        <asp:TextBox runat="server" />
                        <br/>
                        <asp:Label runat="server" Text='<%#Eval("ProductID") %>' />
                        <br/>
                        <asp:Button runat="server" Text="Add TO cart" OnClientClick="AddToCart('<%#Eval("ProductID") %>');return false;"/>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:ListView>

Whent he program runs, it creates a list of product ID, name and a button.

I want to use this button as "add to cart" functionality. so when a user clicks on button, i want to call a javascript function with productID, and textbox value (as item id and quantity).

How can I pass these values to javascript function in listview.

<asp:Button ... OnClientClick='AddToCart(\"<%#Eval("ProductID") %>\", \"<%#Eval("ProductName") %>\");return false;'/>

您可以将值作为参数传递给js函数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM