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