i want to populate a data from a data base..
i wrote a code for webapplication aspx.cs.. which is perfectly work's
code is
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PopulateRootLevel();
}
}
//select ParentId, GroupName,(select count(*) FROM tree WHERE SubGroup=sc.ParentId) SubGroup,SubGroup FROM tree sc where ParentId=@parentID
private void PopulateRootLevel()
{
SqlConnection objConn = new SqlConnection("Data Source=CDTECHPRO2\\SQLEXPRESS;Initial Catalog=Image;Integrated Security=True");
SqlCommand objCommand = new SqlCommand("select ParentId,GroupName,(select count(*) FROM tree WHERE SubGroup=sc.ParentId) childnodecount FROM tree sc where SubGroup IS NULL", objConn);
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, TreeView1.Nodes);
}
private void PopulateNodes(DataTable dt, TreeNodeCollection nodes)
{
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
tn.Text = dr["GroupName"].ToString();
tn.Value = dr["ParentId"].ToString();
nodes.Add(tn);
//If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = ((int)dr["childnodecount"] > 0);
}
}
private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection("Data Source=CDTECHPRO2\\SQLEXPRESS;Initial Catalog=Image;Integrated Security=True");
SqlCommand objCommand = new SqlCommand("select ParentId,GroupName,(select count(*) FROM tree " + "WHERE SubGroup=sc.ParentId) childnodecount FROM tree sc where SubGroup=@SubGroup", objConn);
objCommand.Parameters.Add("@SubGroup", SqlDbType.Int).Value = parentid;
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.ChildNodes);
}
protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
int s = int.Parse(e.Node.Value);
PopulateSubLevel(s, e.Node);
}
but it should not work in C# windows application...
PopulateOnDemand insted of what method what method i am going to use to dinamically populate a data... and this event is also not alaliable..
protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)