i have a tree view :
<asp:TreeView ID="testtree1" runat="server" OnSelectedNodeChanged="testtree1_SelectedNodeChanged">
<Nodes>
<asp:TreeNode Expanded="False" Text="Tests" Value="Tests"></asp:TreeNode>
</Nodes>
</asp:TreeView>
i in my .cs file i have this code:
protected void testtree1_SelectedNodeChanged(object sender, EventArgs e)
{
if (testtree1.SelectedNode.Text == "Tests")
{
con.Open();
SqlCommand cmdd = new SqlCommand("select count(Name) from TypeOfWork");
cmdd.Connection = con;
int idcount = Convert.ToInt32(cmdd.ExecuteScalar());
SqlCommand cmd = new SqlCommand("select Name from TypeOfWork");
cmd.Connection = con;
string[] nid = new string[idcount];
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < idcount; i++)
{
nid[i] = ds.Tables[0].Rows[i]["Name"].ToString().Trim();
testtree1.Nodes.Add(new TreeNode(nid[i]));
}
}
}
else
{
string tstr = testtree1.SelectedNode.Text;
con.Open();
SqlCommand cmd = new SqlCommand("select TypeOfWorkID from TypeOfWork where Name='" + tstr + "'");
cmd.Connection = con;
int tid = Convert.ToInt32(cmd.ExecuteScalar());
SqlCommand cmdd = new SqlCommand("select count(Name) from CategoryLevel1 where TypeOfWorkID='" + tid + "'");
cmdd.Connection = con;
int idcount = Convert.ToInt32(cmdd.ExecuteScalar());
SqlCommand cmd1 = new SqlCommand("select Name from CategoryLevel1 where TypeOfWorkID='" + tid + "'");
cmd1.Connection = con;
string[] nid = new string[idcount];
SqlDataAdapter da = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < idcount; i++)
{
nid[i] = ds.Tables[0].Rows[i]["Name"].ToString().Trim();
TreeNode child1 = new TreeNode();
child1.Text = nid[i];
testtree1.Nodes.Add(child1);
}
}
}
}
the problem here is i am getting a tree getting the correct data but not getting the tree view as it should be.
the root is Tests
when i am clicking it i am getting Civil
and RVI
but they are not as tree view they are comming under the tests
and when i am clicking Civil
or RVI
its childnodes are coming under the whole thing not as a normal tree ... what to do?
any help