Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
i have a treeview binded from an sql database.Parent and child nodes have their navigateurl proprety set to a page ..But on each post back i can't maintain the treeview status...What shuld i do for the sam

following is my code
protected void Page_Load(object sender, EventArgs e)
{

PopulateNodes();
if (Request.QueryString["uid"] != null || Request.QueryString["cid"] != null)
{
getData();
}

}
public void PopulateNodes()
{
DataSet dst = GetTreeViewData();
foreach (DataRow masterRow in dst.Tables["Universities"].Rows) // Loop over the rows.
{
TreeNode masterNode = new TreeNode(masterRow["u_name"].ToString());
masterNode.Value = masterRow["uid"].ToString();
masterNode.NavigateUrl = "~/coursedetails.aspx?uid=" + masterRow["uid"].ToString();
TreeView1.Nodes.Add(masterNode);
foreach (DataRow childRow in masterRow.GetChildRows("Children"))
{
TreeNode childNode = new TreeNode(childRow["c_name"].ToString());
childNode.NavigateUrl = "~/coursedetails.aspx?cid=" + childRow["cid"].ToString();
childNode.Value = childRow["cid"].ToString();
masterNode.ChildNodes.Add(childNode);
}
}

}
public DataSet GetTreeViewData()
{
SqlConnection con = new SqlConnection(WebConfigurationManager.AppSettings.Get("mysqlserver"));
SqlDataAdapter dadunivstys = new SqlDataAdapter("SELECT u_name,id as uid FROM tbluniversity", con);
SqlDataAdapter dadcourses = new SqlDataAdapter("SELECT c_name,id as cid,uid,type FROM tblcourses", con);
DataSet dst = new DataSet();
dadunivstys.Fill(dst, "Universities");
dadcourses.Fill(dst, "Courses");
dst.Relations.Add("Children", dst.Tables["Universities"].Columns["uid"], dst.Tables["Courses"].Columns["uid"]);
return dst;
}



public void getData()
{

if(Request.QueryString["cid"]!=null)
{

DataTable dt = new DataTable();
dt = DALSelect.DAL_selectcoursedetails(Request.QueryString["cid"].ToString());
if (dt.Rows.Count > 0)
{
dlstcourse.Visible = true;
}
dlstcourse.DataSource = dt;
dlstcourse.DataBind();

}
if (Request.QueryString["uid"]!= null)
{
DataTable dt = new DataTable();
dt = DALSelect.DAL_selectuniversitydetails(Request.QueryString["uid"].ToString());
dluniversity.DataSource = dt;
dluniversity.DataBind();
if (dt.Rows.Count > 0)
{
dluniversity.Visible = true;

}


}
}
Thanks for any help

Reogeo
Posted
Updated 21-Oct-11 0:49am
v2

1 solution

Hi,
You can try this....

1)Put You Tree-view In update Panel So That Partial Post Back Will Happened....
 
Share this answer
 
Comments
reogeo2008 21-Oct-11 6:49am    
Hi..
I tried the same and doesnt worked ..Anyway Thanks for the help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900