How to Get TextBox value from button click in Nested Gridview

前端 未结 2 567
别那么骄傲
别那么骄傲 2020-12-21 22:58

I have a Nested Gridview having textbox & Button column. How to display value of textbox in alert when Button Click by using jquer

相关标签:
2条回答
  • 2020-12-21 23:37

    You can try:

    <asp:TemplateField>
        <ItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server" />
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="showText(this); return false;" />
        </ItemTemplate>
    </asp:TemplateField>
    

    with the following showText function, which looks for a text box in the same table cell as the button that was clicked:

    function showText(btn) {
        alert($(btn).closest('td').find('input[type=text]').val());
    }
    


    UPDATE

    According to your other question, the text box and the button could be inside of a div container. If that is the case, the function showText should be:

    function showText(btn) {
        alert($(btn).closest('div').find('input[type=text]').val());
    }
    
    0 讨论(0)
  • 2020-12-21 23:40

    In your web.config add clientIDMode like this:

    <pages clientIDMode="Static"></pages>
    

    Then:

    $(function() {
        $("#Button1").click(function(e) {
             e.preventDefault();
             alert($("#TextBox1").val());
        });
    });
    
    0 讨论(0)
提交回复
热议问题