Это текущий код, который у меня есть, и я пытаюсь держать расширение открытым после каждого щелчка мышью по элементу или ссылки sh, но пока ничего не работает. : - (
Что бы я ни пытался, меню не будет оставаться открытым после того, как я нажму на категории.
Я пытаюсь сделать так, чтобы левая навигация оставалась открытой каждый раз, когда я refre sh или клик.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.treenode.collapse?view=netframework-4.8
Пожалуйста, помогите
<asp:TreeView ID="TreeView1" ExpandDepth="0" runat="server"
style="width:270px" ForeColor="Black" HoverNodeStyle-BackColor ="LightBlue"
ShowExpandCollapse="true" PopulateOnDemand="true" NodeWrap="true"
NodeStyle-CssClass="treeNode"
RootNodeStyle-CssClass="rootNode"
LeafNodeStyle-CssClass="leafNode" ViewStateMode="Enabled"
>
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Configuration
Imports Microsoft.VisualBasic
Imports System.Web.HttpContext
Imports System.Web.UI.WebControls
Partial Class Reports
Inherits Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim Levels As String
Levels = Request.QueryString("Level")
If Not IsPostBack() Then
'GetMenuItems()
GetTreeViewItems()
End If
Dim Search_Text As String
If Session("Search_Text") <> "" Then
Search_Text = Session("Search_Text")
If Search_Text.Contains("Question:") Then
Search_Text = Search_Text.Substring(10, Search_Text.Length - 10)
SqlDataSource5.SelectCommand = "select distinct rr.Bset_Source, 'Home'+replace(rr.Bset_Location,'/','_')+'.PNG' Screenshot_FileName, rr.Bset_Location path, BA.AllDescriptions, rr.Bset_Name name,rr.BSET_URL_Asset, BA.Question1, BA.Question2, BA.Question3 from [CBA_Control].[RR_Bsets_Categories_Plus_H] rr inner join [CBA_Control].[RR_Bsets_Plus] BA on rr.Bset_SourceID = BA.Bset_SourceID " & _
" where Question1 like '" & Search_Text & "%' or Question2 like '" & Search_Text & "%' or Question3 like '" & Search_Text & "%'"
ElseIf Search_Text.Contains("Report:") Then
Search_Text = Search_Text.Substring(8, Search_Text.Length - 8)
SqlDataSource5.SelectCommand = "select distinct rr.Bset_Source, 'Home'+replace(rr.Bset_Location,'/','_')+'.PNG' Screenshot_FileName, rr.Bset_Location path, BA.AllDescriptions, rr.Bset_Name name,rr.BSET_URL_Asset, BA.Question1, BA.Question2, BA.Question3 from [CBA_Control].[RR_Bsets_Categories_Plus_H] rr inner join [CBA_Control].[RR_Bsets_Plus] BA on rr.Bset_SourceID = BA.Bset_SourceID " & _
" where rr.Bset_Name like '%" & Search_Text & "%'"
Else
SqlDataSource5.SelectCommand = "select distinct rr.Bset_Source, 'Home'+replace(rr.Bset_Location,'/','_')+'.PNG' Screenshot_FileName, rr.Bset_Location path, BA.AllDescriptions, rr.Bset_Name name,rr.BSET_URL_Asset, BA.Question1, BA.Question2, BA.Question3 from [CBA_Control].[RR_Bsets_Categories_Plus_H] rr inner join [CBA_Control].[RR_Bsets_Plus] BA on rr.Bset_SourceID = BA.Bset_SourceID " & _
" where BA.AllDescriptions like '%" & Search_Text & "%'"
End If
End If
If Levels <> "" Then
SqlDataSource5.SelectCommand = "select distinct rr.Bset_Source, 'Home'+replace(rr.Bset_Location,'/','_')+'.PNG' Screenshot_FileName, rr.Bset_Location path, BA.AllDescriptions, rr.Bset_Name name,rr.BSET_URL_Asset from [CBAControl].[RR_Bsets_Categories_Plus_H] rr inner join [CBA_Control].[RR_Bsets_Plus] BA on rr.Bset_SourceID = BA.Bset_SourceID " & _
"where rr.level_breadcrumb like '" & Levels & "%'"
Dim Title_Header As String
Title_Header = Dlookup("Category_Breadcrumb", "[CBA_Control].[RR_Categories_V2_H]", "Level_Breadcrumb = '" & Levels & "'")
Lbl_Header.Text = Title_Header
End If
End Sub
Public Shared Function Get_ODBC_Connection() As SqlConnection
Dim MyCo As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DC_ConnectionString").ConnectionString)
Get_ODBC_Connection = New SqlConnection(MyCo.ConnectionString)
End Function
Public Shared Function Dlookup(ByVal strField As String, ByVal strDomain As String, ByVal strCondition As String) As String
Dim objcommand As SqlCommand, ObjDataReader As SqlDataReader
Dim sqlSTMT As String
Dim conn As SqlConnection
Try
conn = Get_ODBC_Connection()
conn.Open()
objcommand = conn.CreateCommand
sqlSTMT = "SELECT " & strField & " FROM " & strDomain & " WHERE " & strCondition
objcommand.CommandText = sqlSTMT
ObjDataReader = objcommand.ExecuteReader
ObjDataReader.Read()
If ObjDataReader.HasRows = True Then
Dlookup = ObjDataReader.Item(0).ToString
Else
Dlookup = ""
End If
conn.Close()
objcommand.Dispose()
Catch
Dlookup = ""
Finally
End Try
End Function
Private Sub GetTreeViewItems()
Dim cs As String = ConfigurationManager.ConnectionStrings("DC_ReportingConnectionString").ConnectionString
Dim con As SqlConnection = New SqlConnection(cs)
Dim da As SqlDataAdapter = New SqlDataAdapter("DCB_Control.spGetTreeViewItems", con)
da.SelectCommand.CommandType = CommandType.StoredProcedure
Dim ds As DataSet = New DataSet()
da.Fill(ds)
ds.Relations.Add("ChildRows", ds.Tables(0).Columns("ID"), ds.Tables(1).Columns("ParentId"))
ds.Relations.Add("grandChildRows", ds.Tables(1).Columns("ID"), ds.Tables(2).Columns("ParentId"))
For Each level1DataRow As DataRow In ds.Tables(0).Rows
Dim treeNode As TreeNode = New TreeNode()
treeNode.Text = level1DataRow("Category").ToString()
treeNode.NavigateUrl = level1DataRow("NavigateURL").ToString()
Dim level2DataRows As DataRow() = level1DataRow.GetChildRows("ChildRows")
For Each level2DataRow As DataRow In level2DataRows
Dim childTreeNode As TreeNode = New TreeNode()
childTreeNode.Text = level2DataRow("Category").ToString()
childTreeNode.NavigateUrl = level2DataRow("NavigateURL").ToString()
Dim level3DataRows As DataRow() = level2DataRow.GetChildRows("grandChildRows")
For Each level3DataRow As DataRow In level3DataRows
Dim grandchildTreeNode As TreeNode = New TreeNode()
grandchildTreeNode.Text = level3DataRow("Category").ToString()
grandchildTreeNode.NavigateUrl = level3DataRow("NavigateURL").ToString()
childTreeNode.ChildNodes.Add(grandchildTreeNode)
Next
treeNode.ChildNodes.Add(childTreeNode)
Next
TreeView1.Nodes.Add(treeNode)
Next
End Sub
Public Function FormatUrl_Preview(ByVal Screenshot_FileName As String) As String
Dim File_path As String
File_path = "C:\J\" & Screenshot_FileName
Dim file_instance As New FileInfo(File_path)
If file_instance.Exists Then
FormatUrl_Preview = "http://Screenshot/" & Screenshot_FileName
Else
FormatUrl_Preview = ""
End If
End Function
Public Function Format_Preview(ByVal Screenshot_FileName As String) As String
Dim File_path As String
File_path = "C:\J\" & Screenshot_FileName
Dim file_instance As New FileInfo(File_path)
If file_instance.Exists Then
Format_Preview = "Preview"
Else
Format_Preview = ""
End If
End Function
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim level1 As String
level1 = DropDownList1.SelectedValue
If level1 = "-1" Then
SqlDataSource2.SelectCommand = "select null ID, '-1' Level_Breadcrumb, '--All Categories--' RRCategory union SELECT ID, Level_Breadcrumb, RRCategory FROM [DC_Reporting].[DCB_Control].[RR_Categories_V2_H] where Hlevel = 2 order by id"
Else
SqlDataSource2.SelectCommand = "select null ID, '-1' Level_Breadcrumb, '--All Categories--' RRCategory union SELECT ID, Level_Breadcrumb, RRCategory FROM [DC_Reporting].[DCB_Control].[RR_Categories_V2_H] where Hlevel = 2 and level_breadcrumb like '" & level1 & ".%' and len(level_breadcrumb) < 6 order by id"
End If
DropDownList2.DataBind()
lbl_Level.Text = level1
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList2.SelectedIndexChanged
Dim level2 As String
level2 = DropDownList2.SelectedValue
If level2 = "-1" Then
lbl_Level.Text = DropDownList1.SelectedValue
Else
SqlDataSource3.SelectCommand = "select null ID, '-1' Level_Breadcrumb, '--All Categories--' RRCategory union SELECT ID, Level_Breadcrumb, RRCategory FROM [DC_Reporting].[DCB_Control].[RR_Categories_V2_H] where Hlevel = 3 and level_breadcrumb like '" & level2 & ".%'" ' and len(level_breadcrumb) < 8"
End If
DropDownList3.DataBind()
lbl_Level.Text = level2
End Sub
Protected Sub DropDownList3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList3.SelectedIndexChanged
Dim level3 As String
level3 = DropDownList3.SelectedValue
If level3 = "-1" Then
lbl_Level.Text = DropDownList2.SelectedValue
Else
lbl_Level.Text = level3
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SqlDataSource5.SelectCommand = "select distinct rr.Bset_Source, 'Home'+replace(rr.Bset_Location,'/','_')+'.PNG' Screenshot_FileName, rr.Bset_Location path, BA.AllDescriptions, rr.Bset_Name name,rr.BSET_URL_Asset from [DCB_Control].[RR_Bsets_Categories_Plus_H] rr inner join [DCB_Control].[RR_Bsets_Plus] BA on rr.Bset_SourceID = BA.Bset_SourceID " & _
"where rr.level_breadcrumb like '" & lbl_Level.Text & "%'"
GridView1.DataBind()
End Sub
End Class