You must Sign In to post a response.
  • Category: ASP.NET

    How to make a nested datalist control?


    I am having two sqlserver database tables named as: "employee" and "employee_details". With the "employee" table, only "employee_id" and "employee_name" are there. And with the "employee_details" table, country, city and state of all the employees are mentioned with the "employee_id".

    Now, I am fetching all the "employee_name" from the "employee" table and displaying these data to a datalist control and then I put another datalist control inside this datalist control, which will show the country,city and state of each related employee.

    The outer datalist control is displaying all the necessary data, but how I can relate the inner datalist control to the outer datalist control to display the related country,city and state for each and every employee of the outer datalist control?

    Please let me know it.
  • #763699
    Hi Arjit,

    first prepare query for employee details and bind to parent grid, and parent grid onitemdatabound event of datalist based on parent row employee id bind your child datalist with details.

    Refer below code

    protected void dl_OnItemDataBound(object sender, DataListItemEventArgs e)
    if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
    string EmployeeId = //get parent grid employee id;
    DataList dlEmployeeDetails = e.Row.FindControl("dlEmployeeDetails") as DataList;
    cmd = new SqlCommand("Get_Employee_Details", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@Employee_ID", StuentId);

    dt = new DataTable();
    da = new SqlDataAdapter(cmd);
    if (dt.Rows.Count > 0)
    dlEmployeeDetails.DataSource = dt;
    catch (Exception ex)


    If you want more details regarding this nested grid bind then I suggest you to refer below link, here I clearly explain you how to achieve this task ""

    Hope this will helpful to you....

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763790
    Hai Arijit Das,
    Yes, you can make the nested data-list controls by adding the inner data-list at run item under the itemdatabound event handler of the master data-list control.
    On ItemDataBound eventhandler, create another DataList control and fill the values based on the main datalist control.
    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #763817
    You can have nested data list in your page.

    Have the data list inside the item template of the parent data list

    Assign the data source for the parent data list. In the itemdatabound event you can get the details for the particular main table.

    assign the data source and bind data for a particular data list using findcontrol

    By Nathan
    Direction is important than speed

  • Sign In to post your comments