简体   繁体   English

在vb.net中选中复选框时,将表行的值传递给带有json的ajax

[英]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. 我有一个包含7列数据的表。复选框用于选定的多行数据。 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. 当我选择单个复选框或可能是多个复选框时,选定的行数据与Ajax json一起传递给后面代码中的vb.net代码。 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. 如果我理解的正确,则需要选择带有选中复选框的行,并将该行的数据传递给ajax。 Yes, this possible, but please provide your code first. 是的,可以这样做,但是请先提供您的代码。 This is the way how to iterate over tr with checkbox cheked. 这是如何在选中复选框的情况下遍历tr的方法。

<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: 像这样遍历已过滤的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. 在ajax调用中,必须将方法相应地更改为PUT,POST或DELETE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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