简体   繁体   中英

Pass value of table row to ajax with json when checkbox is checked in vb.net

I have a table that contains 7 columns with data.Checkbox is use for selected multiple row of data. When i am selecting single checkbox or may be multiple then selected row data pass with ajax json with function to vb.net code in code behind. So how can it possible ?

Any help will be appreciate.

If I understand you correct, you need select rows with selected checkbox and pass data of this rows to ajax. Yes, this possible, but please provide your code first. This is the way how to iterate over tr with checkbox cheked.

<script type="text/javascript">
        $(document).ready(function () {
            $('#MainContent_gvOrders  tr:has(:checkbox:checked)').filter(function () {
                //Insert your ajax call here. You must use jQuery foreach to be able work with each of rows that match criteria.
                });
        });
    </script>

Something like that to iterate over filtered tr:

     $("div.test-block").each(function () {
            var id = $(this).find('input[type=hidden]').val();
            var style = $(this).find("h3").text();
            var option = $(this).find("a").text();
            var selected;
            if (option == "Добавить") {
                selected = false;
            }
            else if (option == "Добавлено") {
                selected = true;
            }
            //Данные
            var json = "{'Id': " + id + ", 'UserGUID':'" + $("#MainContent_guid").val() + "', 'Style':'" + style + "', 'Selected':'" + selected + "'}"
            $.ajax({
                type: "PUT",
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                url: "/api/usersprofiles/" + id,
                data: json,
                success: function () {
                    setTimeout(function () {
                        window.location.replace("default.aspx");
                    }, 3000);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    alert(err.Message);
                }
            });
        });

In ajax call you must change method accordingly to PUT, POST or DELETE.

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