locked
How do i call data from Nested Datalist B and display the data on modal using Jquery or Javascript RRS feed

  • Question

  • User-2074858223 posted

    Hi please i want to call a data from Nested Datalist B and display the data on Modal popup using either Jquery or JavaScript

    below is my markups

     <form id="form1" runat="server">
        <div>
            <asp:DataList ID="dlCustomers" runat="server" OnItemDataBound="dlCustomers_ItemDataBound">
                <HeaderTemplate>
                    <table>
                        <tr>
                            <th>
                                Name
                            </th>
                            <th>
                                City
                            </th>
                            <th>
                                Order
                            </th>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <asp:Label ID="lblContactName" runat="server" Text='<%#Eval("ContactName")%>'></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="lblCity" runat="server" Text='<%#Eval("City")%>'></asp:Label>
                        </td>
                        <td>
                            <asp:DataList ID="dlOrders" runat="server">
                                <HeaderTemplate>
                                    <table>
                                        <tr>
                                            <th>
                                                Order Id
                                            </th>
                                            <th>
                                                Order Date
                                            </th>
                                            <th>
                                                View
                                            </th>
                                        </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td>
                                            <asp:Label ID="lblOrderId" Text='<%#Eval("OrderId")%>' runat="server" />
                                        </td>
                                        <td>
                                            <asp:Label ID="lblDate" Text='<%#Convert.ToDateTime(Eval("OrderDate")).ToString("dd/MM/yyyy")%>'
                                                runat="server" />
                                        </td>
                                        <td>
                                            <asp:Button ID="Button1" runat="server" Text="View" CssClass="btn btn-default" />
                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <tr runat="server" visible="<%#bool.Parse((dlCustomers.Items.Count==0).ToString())%>">
                                        <td colspan="3">
                                            <asp:Label ID="Label1" runat="server" Text="No Record Found!">
                                            </asp:Label>
                                        </td>
                                    </tr>
                                    </table>
                                </FooterTemplate>
                            </asp:DataList>
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:DataList>
        </div>
        <br />
    Friday, January 5, 2018 5:19 PM

All replies

  • User-1838255255 posted

    Hi micah2012,

    After reading your description and codes, if you want to through click some button then show this datalist data or some other methods to show data, please give us more detailed description. 

    Best Regards,

    Eric Du 

    Monday, January 8, 2018 1:39 PM
  • User-2074858223 posted

    I just have a nested datalist B inside Datalist A , now datalist A displayes records from A Table in Database while nested Datalist B displays records from table B in Database, now all i want to do is to call the Nested datalist in B and display it as well on Modal popup.

    Monday, January 8, 2018 3:37 PM
  • User-1838255255 posted

    Hi micah2012,

    According to your description, i make a sample in my side, it works. Please check:

    <head runat="server">
        <title></title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script>
            $(function () {
                $("td").click(function () {
                    debugger;
                    var data = $(this).children("span").text();
                    alert(data);
                    return false;
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:DataList ID="dlCustomers" runat="server" RepeatLayout="Table"
                    RepeatColumns="2" OnItemDataBound="dlCustomers_ItemDataBound">
                    <HeaderTemplate>
                        <table>
                            <tr>
                                <th>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Eval("Name")%>'></asp:Label>
                                </th>
                                <th>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Id")%>'></asp:Label>
                                </th>
                            </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td>
                                <asp:DataList ID="InsideDl" runat="server">
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("NName")%>'></asp:Label>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Eval("NId")%>'></asp:Label>
                                    </ItemTemplate>
                                </asp:DataList>
                            </td>
                        </tr>
                        </table>
                    </ItemTemplate>
                </asp:DataList>
            </div>
        </form>
    </body>
    
    DataTable dt = new DataTable();
            DataTable newdt = new DataTable();
    
            protected void Page_Load(object sender, EventArgs e)
            {
                newdt.Columns.Add("Name", typeof(string));
                newdt.Columns.Add("Id", typeof(string));
                newdt.Rows.Add("Cathy", "1");
                dlCustomers.DataSource = newdt;
                dlCustomers.DataBind();
    
    
                dt.Columns.Add("NName", typeof(string));
                dt.Columns.Add("NId", typeof(string));
                dt.Rows.Add("Eric", "3");
    
                Session["table"] = dt;
    
            }
    
            protected void dlCustomers_ItemDataBound(object sender, DataListItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    DataList dtl = e.Item.FindControl("InsideDl") as DataList;
                    dtl.DataSource = (DataTable)Session["table"];
                    dtl.DataBind();
                }
            }

    Best Regards,

    Eric Du 

    Tuesday, January 9, 2018 12:50 PM