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 thisEverything 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()+" "+" ";
}
else
{
Value += row["Name"].ToString()+" "+" ";
}
TreeNode child = new TreeNode
{
Text = Value.ToString(),
Value = row["Id"].ToString()
};
if (parentId == 0)
{
TreeView1.Nodes.Add(child);
DataTable dtChild = this.GetData("SELECT Id, Name,VehicleType,Capacity FROM Bikes WHERE VehicleTypeId = " + child.Value);
PopulateTreeView(dtChild, int.Parse(child.Value), child);
}
else
{
treeNode.ChildNodes.Add(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;
sda.Fill(dt);
}
}
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" />
</asp:TreeView>