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

    how to display child nodes with headers and keeping the child nodes in a table

    i need to get the column names form datatable/dataset and display them in the child nodes of the treeview below is the code which gives treeview structure for this treeview i have child nodes and for those child nodes if need to display headers how can i do this

    Everything is done but i need to get those child nodes in a table with table structure and headers for that child nodes how can i do this

    Image of my treeview

    Cars//This is parent node1

    Alto 4 wheeler 4 //child node1 for parent node1

    WagonR 4 wheeler 5 //child node2 for parent node1

    Scorpio 4 wheeler 6 //child node3 for parent node1

    Duster 4 wheeler 4 //child node4 for parent node1

    Bikes//this is parent node2

    Discover 2 wheeler 2 //child node1 for parent node2

    Avenger 2 wheeler 2 //child node2 for parent node2

    Unicorn 2 wheeler 2 //child node3 for parent node2

    Karizma 2 wheeler 2 //child node4 for parent node2

    code behind code-

    protected void Page_Load(object sender, EventArgs e)
    UploadStatusLabel.Text = "";
    if (!this.IsPostBack)
    DataTable dt = this.GetData("SELECT Id, Name FROM Cars");
    this.PopulateTreeView(dt, 0, null);
    private void PopulateTreeView(DataTable dtParent, int parentId, TreeNode treeNode)
    foreach (DataRow row in dtParent.Rows)
    string Value=string.Empty;
    if (dtParent.Columns.Count > 2)
    Value += row["Name"].ToString()+ " "+" ";
    Value += row["VehicleType"].ToString()+ " "+" ";
    Value += row["Capacity"].ToString()+" "+" ";
    Value += row["Name"].ToString()+" "+" ";
    TreeNode child = new TreeNode
    Text = Value.ToString(),
    Value = row["Id"].ToString()
    if (parentId == 0)

    DataTable dtChild = this.GetData("SELECT Id, Name,VehicleType,Capacity FROM Bikes WHERE VehicleTypeId = " + child.Value);
    PopulateTreeView(dtChild, int.Parse(child.Value), child);
    private DataTable GetData(string query)
    DataTable dt = new DataTable();
    using (SqlConnection con = new SqlConnection(connStr))
    using (SqlCommand cmd = new SqlCommand(query))
    using (SqlDataAdapter sda = new SqlDataAdapter())
    cmd.CommandType = CommandType.Text;
    cmd.Connection = con;
    sda.SelectCommand = cmd;
    return dt;

    aspx page-

    <asp:TreeView ID="TreeView1" runat="server" ImageSet="XPFileExplorer" NodeIndent="15">
    <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
    <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px"
    NodeSpacing="0px" VerticalPadding="2px"></NodeStyle>
    <ParentNodeStyle Font-Bold="False" />
    <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
    VerticalPadding="0px" />
  • #767274
    can anyone please help me out its urgent requirement

  • #767277
    According to your code, this demo you have implemented in you application.
    Have you checked the output image given at last of above link? Is that the same TreeView that you want?
    have you downloaded '' attached in above link and attached it to your sql server?
    Have you created connection string for the same db?

  • #767296

    First get all the vehicle details into treeview and then based on vehicle type bind the sub brands details into treeview nodes.

    Here you should remember parent and child relation ship should be tracked perfectly, refer below link here they explain you everything you just refer below link if you still have doubts please reach out with error details, "".

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

    Blog :

  • Sign In to post your comments