millenniasp
Regular
- Joined
- Nov 12, 2003
- Messages
- 67
I have a treeview in my ASP.NET application. Here is the code to populate the tree
Private Sub PopulateTree()
If Not IsPostBack Then
Dim strConnectionString As String = "Server=localhost;uid=sa;password=;database=CrystalDevelopment"
Dim strSQLRoot As String = "SELECT DISTINCT(GroupName) FROM CrystalReports"
Dim strSQLChild As String = "SELECT GroupName,ReportName FROM CrystalReports"
Dim cnn As SqlConnection
Dim cmRoot As SqlDataAdapter
Dim cmChild As SqlDataAdapter
Dim ds As DataSet
Dim rowRoot As DataRow
Dim rowChild As DataRow
cnn = New SqlConnection(strConnectionString)
ds = New DataSet
cnn.Open()
cmRoot = New SqlDataAdapter(strSQLRoot, cnn)
cmRoot.Fill(ds, "Root")
cmChild = New SqlDataAdapter(strSQLChild, cnn)
cmChild.Fill(ds, "Child")
ds.Relations.Add("RootChild", _
ds.Tables("Root").Columns("GroupName"), _
ds.Tables("Child").Columns("GroupName"))
'Populate the TreeView from the DataSet.
For Each rowRoot In ds.Tables("Root").Rows
nodeRoot = New TreeNode
nodeRoot.Text = rowRoot("GroupName")
TreeView1.Nodes.Add(nodeRoot)
For Each rowChild In rowRoot.GetChildRows("RootChild")
nodeChild = New TreeNode
nodeChild.Text = rowChild("ReportName")
nodeRoot.Nodes.Add(nodeChild)
Next
Next
'Clean up.
ds.Dispose()
cmRoot.Dispose()
cmChild.Dispose()
cnn.Close()
cnn.Dispose()
End If
that works fine. What I need now is when someone selects a node on the treeview, to capture the name of node. I need this to pass on to a query
Dim myNodeName As String
Dim myReport As String
Dim strConnectionString As String
Dim strSQLReport As String
myNodeName =This is where I am having the problem!!!! How do I set the node name?
strConnectionString = "Server=localhost;uid=sa;password=;database=CrystalDevelopment"
strSQLReport = "SELECT FullReportName FROM CrystalReports WHERE ReportName = " & myNodeName
myda = New SqlDataAdapter(strSQLReport, strConnectionString)
ds = New DataSet
myda.Fill(ds, "ReportName")
myReport = ds.Tables("ReportName").Columns("FullReportName").ToString
ExportReport(myReport)
Any and all help would be greatly appreciated!!!!
Private Sub PopulateTree()
If Not IsPostBack Then
Dim strConnectionString As String = "Server=localhost;uid=sa;password=;database=CrystalDevelopment"
Dim strSQLRoot As String = "SELECT DISTINCT(GroupName) FROM CrystalReports"
Dim strSQLChild As String = "SELECT GroupName,ReportName FROM CrystalReports"
Dim cnn As SqlConnection
Dim cmRoot As SqlDataAdapter
Dim cmChild As SqlDataAdapter
Dim ds As DataSet
Dim rowRoot As DataRow
Dim rowChild As DataRow
cnn = New SqlConnection(strConnectionString)
ds = New DataSet
cnn.Open()
cmRoot = New SqlDataAdapter(strSQLRoot, cnn)
cmRoot.Fill(ds, "Root")
cmChild = New SqlDataAdapter(strSQLChild, cnn)
cmChild.Fill(ds, "Child")
ds.Relations.Add("RootChild", _
ds.Tables("Root").Columns("GroupName"), _
ds.Tables("Child").Columns("GroupName"))
'Populate the TreeView from the DataSet.
For Each rowRoot In ds.Tables("Root").Rows
nodeRoot = New TreeNode
nodeRoot.Text = rowRoot("GroupName")
TreeView1.Nodes.Add(nodeRoot)
For Each rowChild In rowRoot.GetChildRows("RootChild")
nodeChild = New TreeNode
nodeChild.Text = rowChild("ReportName")
nodeRoot.Nodes.Add(nodeChild)
Next
Next
'Clean up.
ds.Dispose()
cmRoot.Dispose()
cmChild.Dispose()
cnn.Close()
cnn.Dispose()
End If
that works fine. What I need now is when someone selects a node on the treeview, to capture the name of node. I need this to pass on to a query
Dim myNodeName As String
Dim myReport As String
Dim strConnectionString As String
Dim strSQLReport As String
myNodeName =This is where I am having the problem!!!! How do I set the node name?
strConnectionString = "Server=localhost;uid=sa;password=;database=CrystalDevelopment"
strSQLReport = "SELECT FullReportName FROM CrystalReports WHERE ReportName = " & myNodeName
myda = New SqlDataAdapter(strSQLReport, strConnectionString)
ds = New DataSet
myda.Fill(ds, "ReportName")
myReport = ds.Tables("ReportName").Columns("FullReportName").ToString
ExportReport(myReport)
Any and all help would be greatly appreciated!!!!