Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I make that?

Status
Not open for further replies.

neegottlob

Programmer
Mar 26, 2006
22
BG
Hello,
I have to make a treeview dinamically taking the source from the database. So I made that but I would like to make the nodes to follow the urls - the treeview should be a kind of a sitemap too because the same database is used to fill gridview controls that are related one after another. For example may databes in short is like:

TABLE "MainProd" (
"MainProdID" "int" --> this is PriKey
"MnName" nvarchar (40) NOT NULL ,....
..........
"Info" nvarchar (40) ...,
)

*-->"MainProd" (1 to infinity) "1MainProd"

Table "1MainProd"(
1MainProdID --> PriKey
1MainProdName
........
MainProdID ---> ForKey
)

*-->"1MainProd" (1 to infinity) "2MainProd"

Table "2MainProd"(
2MainProdID --> PriKey
2MainProdName
........
1MainProdID ---> ForKey
)

So is their any "trick" that I can make the nodes to follow a navigation url like: "theNameOfTheNode.aspx".

I'll really appreciate any help or advice.
Thank You!
 
Your post is a little confusing. Do you want help with ASP.net or SQL?

Take a breath and explain yourself as if you were talking to a six year old. I've had alot of coffee today so I'm flying fast but low.


Yet another unchecked rambling brought to you by:
Oddball
 
it is BOTH:)
What exactly do you want to explain:) This is the ASP source but I do not know how to put the NAVIGATION that should be like i explained above.

Private Sub Node_Populate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs)

If e.Node.ChildNodes.Count = 0 Then

Select Case e.Node.Depth

Case 0

FillAuthors(e.Node)

Exit Sub

Case 1

FillTitlesForAuthors(e.Node)

Exit Sub

End Select

End If

End Sub



Private Sub FillAuthors(ByVal node As TreeNode)


Dim connString As String = ConfigurationManager.ConnectionStrings("autodib").ConnectionString

Dim connection As New OleDb.OleDbConnection(connString)

Dim command As New OleDb.OleDbCommand("SELECT * from Kategoria", connection)

Dim adapter As New OleDb.OleDbDataAdapter(command)

Dim authors As New DataSet()

adapter.Fill(authors)

If authors.Tables.Count > 0 Then

Dim row As DataRow
For Each row In authors.Tables(0).Rows

Dim NewNode As TreeNode = New TreeNode(row("CategorID").ToString() + " " + row("CatName").ToString(), row("CatInfo").ToString())

NewNode.PopulateOnDemand = True

NewNode.SelectAction = TreeNodeSelectAction.Expand

node.ChildNodes.Add(NewNode)

Next

End If

End Sub



Private Sub FillTitlesForAuthors(ByVal node As TreeNode)

Dim CategorID As String = node.Value
Dim connString As String = ConfigurationManager.ConnectionStrings("autodib").ConnectionString()

Dim connection As New OleDb.OleDbConnection(connString)

Dim command As New OleDb.OleDbCommand("Select Produkti.ProdID,Produkti.ImeProd From Produkti" + " Inner Join Kategoria on Kategoria.CategorID = Produkti.CategorID " + " Where Kategoria.CategorID = '" + CategorID + "'", connection)

Dim adapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(command)

Dim titlesForAuthors As DataSet = New DataSet()

adapter.Fill(titlesForAuthors)

If titlesForAuthors.Tables.Count > 0 Then

Dim row As DataRow
For Each row In titlesForAuthors.Tables(0).Rows
Dim NewNode As TreeNode
NewNode = New TreeNode(row("ImeProd").ToString(), row("ProdID").ToString())

NewNode.PopulateOnDemand = False

NewNode.SelectAction = TreeNodeSelectAction.None

node.ChildNodes.Add(NewNode)

Next

End If

End Sub


thanks
 
I can't help this fella but just to make it easyer for others I've ported his code into C# - now no one has an excuse :)

Code:
private void NodePopulate(object sender, TreeNodeEventArgs e)
{
	if (e.Node.ChildNodes.Count == 0)
	{
		select (e.Node.Depth)
		{
			case 0:
				FillAuthors(e.Node);
				return;
			case 1:
				FillTitlesForAuthors(e.Node);
				return;
		}
	}
}

private void FillAuthors(TreeNode node)
{
	string connString = ConfigurationManager.ConnectionStrings("autodib").ConnectionString;
	OleDbConnection connection = new OleDbConnection(connString);

	OleDbCommand command = new OleDbCommand("SELECT * FROM Kategoria", connection);

	OleDbDataAdapter adapter = new OleDbDataAdapter(command);
	
	DataSet authors = new DataSet();

	adapter.Fill(authors);

	if (authors.Tables.Count > 0)
	{
		foreach (DataRow row in authors.Tables(0).Rows)
		{
			TreeNode newNode = new TreeNode(row("CategorId").ToString() + " " + row("CatName").ToString(), row("CatInfo").ToString());
			newNode.PopulateOnDemand = true;
			newNode.SelectAction = TreeNodeSelectAction.Expand;

			node.ChildNodes.Add(newNode);
		}
	}
}

private void FillTitlesForAuthors(TreeNode node)
{
	string CategorID = node.Value;

	OleDbConnection connection = new OleDbConnection(connString);
	OleDbCommand command = new OleDbCommand("SELECT Produkti.ProdID,Produkti.ImeProd " +
						"FROM Produkti INNER JOIN Kategoria ON Kategoria.CategorID = Produkti.CategorID " +
						"WHERE Kategoria.CategorID = '" + CategorID + "'", connection);

	OleDbDataAdapter adapter = new OleDbDataAdapter(command);
	
	DataSet titlesForAuthors= new DataSet();

	titlesForAuthors.Fill(authors);

	if (titlesForAuthors.Tables.Count > 0)
	{
		foreach (DataRow row in titlesForAuthors.Tables(0).Rows)
		{
			TreeNode newNode = null;
			newNode = new TreeNode(row("ImeProd").ToString(), row("ProdID").ToString());
			newNode.PopulateOnDemand = false;
			newNode.SelectAction = TreeNodeSelectAction.None;
			node.ChildNodes.Add(newNode);
		}
	}
}


Yet another unchecked rambling brought to you by:
Oddball
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top