Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I've an asp.net gridview "gvCustomers" which displays the list of customers at the same time I want to display the list of (single / multiple) order(s) placed by the respective customer.

My issue is I'm unable to find the gridview "gvItems" placed inside "gvCustomers" using jQuery

Suggestions will be appreciated.

Thanks

What I have tried:

function LoadOrderItems(orderId) {
            var row1;
            $.ajax({
                type: "POST",
                url: "manageOrders.aspx/PopulateItems",
                data: '{orderId: "' + orderId + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: "true",
                beforeSend: function () {
                    /**/
                },
                success: function (response) {

                    var xmlDoc1 = $.parseXML(response.d);
                    var xml1 = $(xmlDoc1);
                    var orders1 = xml1.find("dsItems");
                    var html1 = '<table id="gvItems">';

                    if (row1 == null) {
                        row1 = $("#<%=gvItems.ClientID %> tr:last-child").clone(true);
                    }

                    $("#<%=gvItems.ClientID %> tr").not($("#<%=gvItems.ClientID %> tr:first-child")).remove();
                    html1 += $("#<%=gvItems.ClientID %>").html();
                    if (orders1.length > 0) {
                        $.each(orders1, function () {
                            html1 += "<tr>";

                            $(row1).find("#lblProduct").html($(this).find("prod_name").text());
                            
                            $("#<%=gvItems.ClientID %>").append(row1);
                            row1 = $("#<%=gvItems.ClientID %> tr:last-child").clone(true);
                            html1 += $(row1).html();
                            html1 += "</tr>";
                        });
                    } else {
                        $("#lblRecordCount").text("");

                        var empty_row = row1.clone(true);
                        $("td:first-child", empty_row).attr("colspan", $("td", row1).length);
                        $("td:first-child", empty_row).attr("align", "center");
                        //$("td:first-child", empty_row).attr("style", "background-color:#FFE6E3");
                        $("td:first-child", empty_row).attr("class", "well");
                        $("td:first-child", empty_row).html("No Data Available");
                        $("td", empty_row).not($("td:first-child", empty_row)).remove();
                        $("#<%=gvItems.ClientID %>").append(empty_row);
                    }
                    html1 += '</table>';
                },
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }
Posted
Updated 2-Apr-20 5:50am
v3

1 solution

Your parent GridView will have multiple rows. If you put a control inside the ItemTemplate of a TemplateField, there will be one instance of that control for every row in the parent grid.

Therefore, asking what the client ID of that control is makes no sense. There will be a difference client ID for every instance of the control. You'll need to find a different way to identify the nested table - for example, by adding a specific CSS class to it.

It also doesn't make sense to have a nested GridView unless you're binding the nested grid on the server. If you're binding the nested grid on the client using AJAX, just add an empty <table> to the item template instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900