Hello All,
I have a tree view control in my aspx page and using stored procedure i have retrieved data from the database to the treeview.While executing it shows no error but the tree view is not visible.It just shows an empty page can anyone please help with this.Do i want to add any additional code ? Whats the problem kindly guide me.
ASPX Code:
<asp:TreeView ID="trpart" runat="server"
ImageSet="Inbox"
OnSelectedNodeChanged="trpart_SelectedNodeChanged"
OnTreeNodePopulate="trpart_TreeNodePopulate" ShowExpandCollapse="False">
<ParentNodeStyle Font-Bold="False" ForeColor="black" />
<HoverNodeStyle Font-Underline="True" />
<SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px"
NodeSpacing="2px" VerticalPadding="0px" />
<NodeStyle HorizontalPadding="0px"
NodeSpacing="2px" VerticalPadding="0px" />
</asp:TreeView>
aspx.cs code:
SqlCommand cmd1;
SqlDataReader dr1;
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
LoadTree();
trpart.ExpandAll();
trpart.Visible = true;
}
protected void LoadTree()
{
trpart.Visible = true;
con.Open();
cmd1 = new SqlCommand("select a.PartID,a.PartName,b.StatusID,b.Status,c.SStatusID,c.Substatus from tblpart a,tblstatus b,tblsubstatus c where c.StatusID=b.StatusID and b.PartID=a.PartID", con);
dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
TreeNode aa = new TreeNode();
aa.Text = dr1["PartName"].ToString();
aa.Value = dr1["PartID"].ToString();
}
trpart.ExpandAll();
trpart.Visible = true;
}
protected void trpart_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
if (e.Node.ChildNodes.Count == 0)
{
switch (e.Node.Depth)
{
case 0:
GetStatus(e.Node);
break;
}
}
}
protected void trpart_SelectedNodeChanged(object sender, EventArgs e)
{
}
protected void GetStatus(TreeNode n)
{
con.Open();
cmd1 = new SqlCommand("select a.PartID,a.PartName,b.StatusID,b.Status,c.SStatusID,c.SubStatus from tblpart a,tblstatus b,tblsubstatus c where c.StatusID=b.StatusID and b.PartID=a.PartID", con);
dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
TreeNode aa = new TreeNode();
aa.Text = dr1["Status"].ToString();
aa.Value = dr1["StatusID"].ToString();
aa.SelectAction = TreeNodeSelectAction.Select;
n.ChildNodes.Add(aa);
}
}
Thanks in advance