简体   繁体   中英

use jquery find repeater checkbox checked value

I have a checkbox template field within a repeater in c#

bind the repeater using asp.net c#

<asp:Repeater ID="rpt_detail" runat="server">
    <ItemTemplate>
        <table>
            <tr>
                <td style="width: 10%; padding-top: 10px;">
                    <input type="checkbox" id="selectit" name="selectit" value='<%# Eval("mdID") %>' />
                </td>
                <td>
                    <asp:Label ID="mdID" runat="server" Visible="false" Text='<%# Eval("mdID") %>'></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lbl_xprice" runat="server" Text='<%# Eval("mdPrice") %>'></asp:Label>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:Repeater>

and javascipt

<script>
    function aaaaa() {
        var selectit = $('input[name="selectit"]').val();

        $.ajax({
            url: "ajaxservice/getinchar.aspx",
            type: 'POST',
            data: { selectw: selectit },
            success: function (result) {
                $("#testview").html(result);
            }
        });
    }
</script>

How can I get checkbox checked value ?

You can loop all the checkboxes in the repeater with jQuery.

<script type="text/javascript">
    function getCheckBoxValues() {
        $('#myRepeater input[type="checkbox"]').each(function () {
            if ($(this).prop('checked') == true) {
                alert($(this).val());
            }
        });
    }
</script>

But in order for this to work you have to wrap the Repeater with a <div> with a unique ID.

<div id="myRepeater">
    <asp:Repeater ID="rpt_detail" runat="server"></asp:Repeater>
</div>

Not really related to the solution, but you are getting duplicate ID's ( selectit ) in your checkboxes inside the Repeater. Better use the asp.net CheckBox Control.

And you can better set the <table> </table> outside the Repeater.

<table id="myRepeater">
    <asp:Repeater ID="rpt_detail" runat="server">
        <ItemTemplate>
            <tr>
                <td> content... </td>
            </tr>
        </ItemTemplate>
    </asp:Repeater>
</table>

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