hi ..sry here's all the code (master.page.cs):
public partial class Site : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
//restore state of treeview
TreeViewState.RestoreTreeView(LinksTreeView, "Woka");
}
protected void TreeViewMain_SelectedNodeChanged(object sender, EventArgs e)
{
if (LinksTreeView.SelectedNode.Value != string.Empty)
{
Server.Transfer(LinksTreeView.SelectedNode.Value);
}
}
protected void TreeViewMain_Unload(object sender, EventArgs e)
{
//save the state of the treeview
TreeViewState.SaveTreeView(LinksTreeView, "Woka");
}
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
//collapse the previous node
if (e.Node.Parent == null)
return;
string strNodeValue = e.Node.Value;
foreach (TreeNode node in e.Node.Parent.ChildNodes)
{
if (node.Value != strNodeValue)
{
node.Collapse();
}
}
}
protected void PopulateNode(Object sender, TreeNodeEventArgs e)
{
// Call the appropriate method to populate a node at a particular level.
switch(e.Node.Depth)
{
case 0:
// Populate the first-level nodes.
PopulateMenu(e.Node);
break;
case 1:
// Populate the second-level nodes.
PopulateColectii(e.Node);
PopulateExpozitii(e.Node);
PopulateEvenimente(e.Node);
PopulateMedia(e.Node);
PopulatePublicatii(e.Node);
PopulateCercetare(e.Node);
PopulateServicii(e.Node);
PopulateDepartamente(e.Node);
PopulateLegislatie(e.Node);
PopulateLinkuri(e.Node);
break;
case 2:
// Populate the third-level nodes.
PopulateItemsColectii(e.Node);
PopulateItemsServicii(e.Node);
break;
default:
// Do nothing.
break;
}
}
void PopulateMenu(TreeNode node)
{
// Query for the product categories. These are the values
// for the second-level nodes.
DataSet ResultSet = RunQuery("Select IDMenu, DenumireMenu, Url, OrdineAfisare From Menu Order by OrdineAfisare");
// Create the second-level nodes.
if(ResultSet.Tables.Count > 0)
{
// Iterate through and create a new node for each row in the query results.
// Notice that the query results are stored in the table of the DataSet.
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
string url = row["Url"].ToString();
string imageurl = "~/images/dot.jpg";
// Create the new node. Notice that the IDMenu is stored in the Value property
// of the node. This will make querying for items in a specific category easier when
// the third-level nodes are created.
TreeNode NewNode = new TreeNode(row["DenumireMenu"].ToString(), row["IDMenu"].ToString(), imageurl, url, "_self");
// Set the PopulateOnDemand property to true so that the child nodes can be
// dynamically populated.
//NewNode.NavigateUrl = row["Url"].ToString();
NewNode.PopulateOnDemand = true;
// Set additional properties for the node.
NewNode.SelectAction = TreeNodeSelectAction.Expand;
// Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateColectii(TreeNode node)
{
// Query for the products of the current category. These are the values
// for the third-level nodes.
DataSet ResultSet = RunQuery("Select DenumireColectie, IDColectie, IDMenu From Colectii Where IDMenu=" + node.Value);
// Create the third-level nodes.
if(ResultSet.Tables.Count > 0)
{
// Iterate through and create a new node for each row in the query results.
// Notice that the query results are stored in the table of the DataSet.
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
// Create the new node.
string url = "ro/Colectii/Colectii.aspx?IDColectie=" + row["IDColectie"].ToString();
string imageurl = "~/images/dot.jpg";
string colectiiValue = "c" + row["IDColectie"].ToString();
TreeNode NewNode = new TreeNode(row["DenumireColectie"].ToString(), colectiiValue, imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
// Set additional properties for the node.
NewNode.SelectAction = TreeNodeSelectAction.Expand;
// Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateExpozitii(TreeNode node)
{
DataSet ResultSet = RunQuery("Select IDMenu, DenumireMenu From Menu where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
int Expozitii = 2;
string StrExpozitii = Convert.ToString(Expozitii);
string url = "ro/Expozitii/ArhivaExpozitii.aspx";
string imageurl = "~/images/dot.jpg";
if (node.Value == StrExpozitii)
{
TreeNode NewNode = new TreeNode("Arhiva Expozitii", "ArhivaExpozitii", imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
}
void PopulateEvenimente(TreeNode node)
{
DataSet ResultSet = RunQuery("Select IDMenu, DenumireMenu From Menu where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
int Evenimente = 3;
string StrEvenimente = Convert.ToString(Evenimente);
string url = "ro/Evenimente/ArhivaEvenimente.aspx";
string imageurl = "~/images/dot.jpg";
if (node.Value == StrEvenimente)
{
TreeNode NewNode = new TreeNode("Arhiva Evenimente", "ArhivaEvenimente", imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
}
void PopulatePublicatii(TreeNode node)
{
DataSet ResultSet = RunQuery("Select DenumireTipPublicatie, IDTipPublicatie, IDMenu From Publicatii Where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
string url = "ro/Publicatii.aspx?IDTipPublicatie=" + row["IDTipPublicatie"].ToString();
string imageurl = "~/images/dot.jpg";
string publicatiiValue = "p" + row["IDCercetare"].ToString();
TreeNode NewNode = new TreeNode(row["DenumireTipPublicatie"].ToString(), publicatiiValue, imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateCercetare(TreeNode node)
{
DataSet ResultSet = RunQuery("Select DenumireCercetare, IDCercetare, IDMenu From Cercetare Where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
string url = "ro/Cercetare/Cercetare.aspx?IDCercetare=" + row["IDCercetare"].ToString();
string imageurl = "~/images/dot.jpg";
string cercetareValue = "ce" + row["IDCercetare"].ToString();
TreeNode NewNode = new TreeNode(row["DenumireCercetare"].ToString(), cercetareValue, imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateServicii(TreeNode node)
{
DataSet ResultSet = RunQuery("Select DenumireServiciu, IDServicii, IDMenu From Servicii Where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
string url = "ro/Servicii/Servicii.aspx?IDServicii=" + row["IDServicii"].ToString();
string imageurl = "~/images/dot.jpg";
string serviciiValue = "s" + row["IDServicii"].ToString();
TreeNode NewNode = new TreeNode(row["DenumireServiciu"].ToString(), serviciiValue, imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateDepartamente(TreeNode node)
{
DataSet ResultSet = RunQuery("Select DenumireDepartament, IDDepartament, IDMenu From Departamente Where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
string url = "ro/Departamente/Departamente.aspx?IDDepartament=" + row["IDDepartament"].ToString();
string imageurl = "~/images/dot.jpg";
string departamenteValue = "d" + row["IDDepartament"].ToString();
TreeNode NewNode = new TreeNode(row["DenumireDepartament"].ToString(), departamenteValue, imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateMedia(TreeNode node)
{
DataSet ResultSet = RunQuery("Select IDMenu, DenumireMenu From Menu where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
int Media = 8;
string StrMedia = Convert.ToString(Media);
string url = "ro/Media/ArhivaMedia.aspx";
string imageurl = "~/images/dot.jpg";
if (node.Value == StrMedia)
{
TreeNode NewNode = new TreeNode("Arhiva Media", "ArhivaMedia", imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
}
void PopulateLegislatie(TreeNode node)
{
DataSet ResultSet = RunQuery("Select DenumireTipLegislatie, IDTipLegislatie, IDMenu From Legislatie Where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
string url = "ro/Legislatie/Legislatie.aspx?IDTipLegislatie=" + row["IDTipLegislatie"].ToString();
string imageurl = "~/images/dot.jpg";
TreeNode NewNode = new TreeNode(row["DenumireTipLegislatie"].ToString(), row["IDTipLegislatie"].ToString(), imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateLinkuri(TreeNode node)
{
DataSet ResultSet = RunQuery("Select NumeCategorieLink, IDCategoryLink, IDMenu From Linkuri Where IDMenu=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
string url = "ro/Linkuri/Linkuri.aspx?IDCategoryLink=" + row["IDCategoryLink"].ToString();
string imageurl = "~/images/dot.jpg";
TreeNode NewNode = new TreeNode(row["NumeCategorieLink"].ToString(), row["IDCategoryLink"].ToString(), imageurl, url, "_self");
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateItemsColectii(TreeNode node)
{
// Query for the products of the current category. These are the values
// for the third-level nodes.
DataSet ResultSet = RunQuery("Select DenumireItemColectie, IDItemColectie, IDColectie From ItemsColectii");
// Create the third-level nodes.
if (ResultSet.Tables.Count > 0)
{
// Iterate through and create a new node for each row in the query results.
// Notice that the query results are stored in the table of the DataSet.
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
if (node.Value == "c" + row["IDColectie"].ToString())
{
string url = "ro/Colectii/ItemsColectii.aspx" + "?IDItemColectie=" + row["IDItemColectie"].ToString();
string imageurl = "~/images/dot.jpg";
// Create the new node.
TreeNode NewNode = new TreeNode(row["DenumireItemColectie"].ToString(), row["IDItemColectie"].ToString(), imageurl, url, "_self");
// Set the PopulateOnDemand property to false because these are leaf nodes and
// do not need to be populated.
NewNode.PopulateOnDemand = true;
// Set additional properties for the node.
NewNode.SelectAction = TreeNodeSelectAction.Expand;
// Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes.Add(NewNode);
}
}
}
}
void PopulateItemsServicii(TreeNode node)
{
// Query for the products of the current category. These are the values
// for the third-level nodes.
DataSet ResultSet = RunQuery("Select DenumireItemServicii, IDServicii, IDItemServicii From ItemsServicii");
// Create the third-level nodes.
if (ResultSet.Tables.Count > 0)
{
// Iterate through and create a new node for each row in the query results.
// Notice that the query results are stored in the table of the DataSet.
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
if (node.Value == "s" + row["IDServicii"].ToString())
{
// Create the new node.
TreeNode NewNode = new TreeNode(row["DenumireItemServicii"].ToString(), row["IDServicii"].ToString());
// Set the PopulateOnDemand property to false because these are leaf nodes and
// do not need to be populated.
NewNode.PopulateOnDemand = true;
// Set additional properties for the node.
NewNode.SelectAction = TreeNodeSelectAction.Expand;
// Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes.Add(NewNode);
}
}
}
}
DataSet RunQuery(String QueryString)
{
// Declare the connection string. This example uses Microsoft SQL Server and connects to the
// Northwind sample database.
String ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MNIR.mdf;Integrated Security=True;User Instance=True";
SqlConnection DBConnection = new SqlConnection(ConnectionString);
SqlDataAdapter DBAdapter;
DataSet ResultsDataSet = new DataSet();
try
{
// Run the query and create a DataSet.
DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
DBAdapter.Fill(ResultsDataSet);
// Close the database connection.
DBConnection.Close();
}
catch (Exception ex)
{
// Close the database connection if it is still open.
if (DBConnection.State == ConnectionState.Open)
{
DBConnection.Close();
}
Message.Text = "Unable to connect to the database.";
}
return ResultsDataSet;
}
}