1

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 ?

VDWWD
  • 35,079
  • 22
  • 62
  • 79
余致賢
  • 67
  • 2
  • 4
  • You mean you have multiple checkboxes and you want to send the checked ones? Have a look at: http://stackoverflow.com/questions/9493531/send-multiple-checkbox-data-to-php-via-jquery-ajax – axel.michel Jan 02 '17 at 14:04
  • If you generate unique IDs to every checkbox, you can get their values in a loop as you do it for one checkbox in the `aaaaa` function. – Ferdinand Prantl Jan 02 '17 at 16:41

1 Answers1

0

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>
VDWWD
  • 35,079
  • 22
  • 62
  • 79