⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultvb.aspx.vb

📁 Telerik是很大的第三方软件制造商
💻 VB
字号:

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports Telerik.WebControls


Namespace Telerik.MenuExamplesVBNET.Menu.Examples.Design.DataBinding
   
   '/ <summary>
   '/ Summary description for DefaultCS.
   '/ </summary>
   Public Class DefaultVB
      Inherits Telerik.QuickStart.XhtmlPage
      Protected WithEvents RadioButtonList1 As System.Web.UI.WebControls.RadioButtonList
      Protected WithEvents Menu1 As RadMenu
      Protected Label1 As System.Web.UI.WebControls.Label
      Protected DefaultDSN As String = [String].Empty
      
      
      Private Function GetMenuDataSource(inputDSN As String) As DataSet
         Dim OldDbCon As New OleDbConnection(inputDSN)
         OldDbCon.Open()
         Dim MenuDataAdaptor As New OleDbDataAdapter("SELECT Text,idtext,parentIdtext FROM Links", OldDbCon)
         Dim MenuDataLoader As New DataSet()
         MenuDataAdaptor.Fill(MenuDataLoader)
         OldDbCon.Close()
         Return MenuDataLoader
      End Function 'GetMenuDataSource
      
      
      ' The old DataBind method uses the GenerateMenu, which sets 
      ' the data Source, and then cycles trough the dataset calling 
      ' RecursivelyPopulate which sets recursively the control trees
      Private Sub GenerateMenu(inputDSN As String)
         Dim OldDbCon As New OleDbConnection(inputDSN)
         OldDbCon.Open()
         Dim adapter As New OleDbDataAdapter("SELECT id,parentId,Text,idtext,parentIdtext FROM Links WHERE status=1", OldDbCon)
         Dim ds As New DataSet()
         adapter.Fill(ds)
         ds.Relations.Add("NodeRelation", ds.Tables(0).Columns("id"), ds.Tables(0).Columns("parentId"), False)
         Dim MainGroup As New MenuGroup()
         MainGroup.Flow = PresentationDirection.Horizontal
         Menu1.RootGroup = MainGroup
         Menu1.ImagesBaseDir = "~/Menu/Examples/Programming/DataBinding/Images/"
         Dim dbRow As DataRow
         For Each dbRow In  ds.Tables(0).Rows
            If dbRow.IsNull("parentId") Then
               Dim item As New Telerik.WebControls.MenuItem()
               item.Text = dbRow("Text").ToString()
               MainGroup.AddItem(item)
               RecursivelyPopulate(dbRow, item)
            End If
         Next dbRow
         OldDbCon.Close()
      End Sub 'GenerateMenu
      
      
      Private Sub RecursivelyPopulate(dbRow As DataRow, item As Telerik.WebControls.MenuItem)
         Dim CurrentGroup As New MenuGroup()
         Dim childRow As DataRow
         For Each childRow In  dbRow.GetChildRows("NodeRelation")
            Dim childItem As New Telerik.WebControls.MenuItem()
            childItem.Text = childRow("Text").ToString()
            CurrentGroup.AddItem(childItem)
            RecursivelyPopulate(childRow, childItem)
         Next childRow
         If CurrentGroup.Items.Count > 0 Then
            item.RightLogo = "arrow_right.gif"
            item.ChildGroup = CurrentGroup
         End If
      End Sub 'RecursivelyPopulate
      
      Private Sub processMainItems()
         
         If Not (Menu1.RootGroup Is Nothing) And Menu1.RootGroup.Items.Count > 0 Then
            Dim i As Integer
            For i = 0 To Menu1.RootGroup.Items.Count - 1
               Menu1.RootGroup.Items(i).CssClass = "MainItem"
               Menu1.RootGroup.Items(i).CssClassOver = "MainItemOver"
            Next i
         End If
      End Sub 'processMainItems
      
      
      Private Sub MenuRealBind()
         ' here we set the Data source string (DSN) required by ADO.NET classes
         DefaultDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("menudata.mdb")
         Select Case Convert.ToInt32(RadioButtonList1.Items(RadioButtonList1.SelectedIndex).Value)
            Case 1
               ' here we use the new Asp.NET DataBinding mechanism
               Menu1.EnableGroupChildrenImage = True
               Menu1.DataFieldID = "idtext" 'idtext
               Menu1.DataFieldParentID = "parentIdtext" 'parentIdtext
               Menu1.DataSource = GetMenuDataSource(DefaultDSN).Tables(0).DefaultView
               Menu1.DataBind()
               
               Menu1.RootGroup.Flow = PresentationDirection.Horizontal
               Label1.Text = "Menu is data-bound using Asp.NET DataBind() method"
            Case 2
               GenerateMenu(DefaultDSN)
               Label1.Text = "Menu is data-bound using RecursivelyPopulate() method"
            Case Else
               GenerateMenu(DefaultDSN)
               Label1.Text = "Menu is data-bound using RecursivelyPopulate() method"
         End Select
      End Sub 'MenuRealBind
      
      
      Private Sub RadioSwitch_Clicked(sender As Object, e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
         MenuRealBind()
         processMainItems()
      End Sub 'RadioSwitch_Clicked
      
      
      Private Sub Evnt_Test(sender As Object, e As MenuEntityInstantiatedEventArgs) Handles Menu1.ItemDataBound
         If Not (e.Item Is Nothing) Then
         End If
         'e.Item.Text = "test_change";
         If Not (e.DataItem Is Nothing) Then
         End If
      End Sub 'Evnt_Test
       
      
      Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
         If Not Page.IsPostBack Then
            MenuRealBind()
            processMainItems()
         End If
      End Sub 'Page_Load
      Protected Overrides Sub OnInit(e As EventArgs)
         '
         ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
         '
         InitializeComponent()
         MyBase.OnInit(e)
      End Sub 'OnInit
      
      
      '/ <summary>
      '/ Required method for Designer support - do not modify
      '/ the contents of this method with the code editor.
      '/ </summary>
      Private Sub InitializeComponent()
      End Sub 'InitializeComponent
   End Class 'DefaultVB 
End Namespace 'Telerik.MenuExamplesVBNET.Menu.Examples.Design.DataBinding

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -