I'm trying make one treeView
with infinite subgroups.
I can add my groups but I couldn't add my subgroups. For subgroup the output shows my group value. My code for subgroup is below: I think there is something wrong with my SQL string but I don't know what is.
private void chilnoddoldur(DataTable dt, TreeNodeCollection treeNodeCollection)
//fill childnodes
{
foreach (DataRow dr in dt.Rows)
{
TreeNode child = new TreeNode();
child.Text = dr["kgr_ad"].ToString();
child.Value = dr["kgr_bsno"].ToString();
if (child.ChildNodes.Count > 0)
{
child.PopulateOnDemand = true;
}
child.SelectAction = TreeNodeSelectAction.SelectExpand;
child.Expand();
child.Selected = true;
treeNodeCollection.Add(child);
}
}
Here is the SQL Code:
SqlConnection conn = b.baglan();
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Open();
SqlCommand cmd = new SqlCommand("select kgr_sno,kgr_ad,kgr_bsno from kulgrp where kgr_bsno=@id", conn);
cmd.Parameters.AddWithValue("@id", kgrSno);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
kgrBsno.ChildNodes.Clear();
chilnoddoldur(dt, kgrBsno.ChildNodes);
conn.Close();