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

📄 defaultvb.aspx.vb

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

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
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.CallbackExamplesVBNET.Callback.Examples.Demos.Contacts
   
   '/ <summary>
   '/ Summary description for _Default.
   '/ </summary>
   Public Class _Default
      Inherits System.Web.UI.Page
      Protected nameBox As System.Web.UI.WebControls.TextBox
      Protected emailBox As System.Web.UI.WebControls.TextBox
      Protected WithEvents personalRadioButton As CallbackRadioButton
      Protected WithEvents workRadioButton As CallbackRadioButton
      Protected groupDropDown As System.Web.UI.WebControls.DropDownList
      Protected avatarDropDown As System.Web.UI.WebControls.DropDownList
      Protected WithEvents contactsFilterDropDown As CallbackDropDownList
      Protected WithEvents saveButton As CallbackImageButton
      Protected WithEvents cancelButton As CallbackImageButton
      Protected LoadingPanel1 As Telerik.WebControls.LoadingPanel
      Protected Img1 As System.Web.UI.HtmlControls.HtmlImage
      Protected bigLoadingPanel As Telerik.WebControls.LoadingPanel
      Protected progressBarLoadingPanel As Telerik.WebControls.LoadingPanel
      Protected Img2 As System.Web.UI.HtmlControls.HtmlImage
      Protected leftPanel As System.Web.UI.WebControls.Panel
      Protected WithEvents contactsGrid As System.Web.UI.WebControls.DataGrid
      
      
      Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
         If Not Page.IsPostBack Then
            dataTable = New DataTable()
            
            dataTable.Columns.Add("Name", GetType(String))
            dataTable.Columns.Add("Email", GetType(String))
            dataTable.Columns.Add("Type", GetType(String))
            
            dataTable.Rows.Add(New Object() {"Joe Satriani", "joe@domain.com", "Personal"})
            dataTable.Rows.Add(New Object() {"Steve Vai", "steve@domain.com", "Personal"})
            dataTable.Rows.Add(New Object() {"Tony Macalpine", "tony@domain.com", "Personal"})
            dataTable.Rows.Add(New Object() {"Brett Garsed", "brett@domain.com", "Work"})
            dataTable.Rows.Add(New Object() {"Rey Mysterio", "ray@wwe.com", "Work"})
            dataTable.Rows.Add(New Object() {"Yngwie Malmsteen", "yngwie@domain.com", "Work"})
            
            BindGrid()
            BindGroupsAndAvatars()
         End If 
      End Sub 'Page_Load
      
      
      Private Property dataTable() As DataTable
         Get
            Return CType(ViewState("table"), DataTable)
         End Get
         Set
            ViewState("table") = value
         End Set
      End Property
      
      
      Private ReadOnly Property dataView() As DataView
         Get
            Dim [source] As New DataView(dataTable)
            Dim selected As ListItem = contactsFilterDropDown.Items(contactsFilterDropDown.SelectedIndex)
            If selected.Value <> "All" Then
               [source].RowFilter = String.Format("Type = '{0}'", selected.Value)
            End If
            
            Return [source]
         End Get
      End Property
      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
      Private Sub contactsFilterDropDown_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles contactsFilterDropDown.SelectedIndexChanged
         Dim [source] As New DataView(dataTable)
         Dim selected As ListItem = contactsFilterDropDown.Items(contactsFilterDropDown.SelectedIndex)
         If selected.Value <> "All" Then
            [source].RowFilter = String.Format("Type = '{0}'", selected.Value)
         End If
         
         BindGrid()
      End Sub 'contactsFilterDropDown_SelectedIndexChanged
      
      
      Private Sub BindGrid()
         contactsGrid.DataSource = dataView
         contactsGrid.DataBind()
      End Sub 'BindGrid
      
      
      Private Sub personalRadioButton_CheckedChanged(sender As Object, e As System.EventArgs) Handles personalRadioButton.CheckedChanged
         BindGroupsAndAvatars()
      End Sub 'personalRadioButton_CheckedChanged
      
      
      Private Sub BindGroupsAndAvatars()
         Dim personalGroups() As String = {"Family", "Friends"}
         Dim workGroups() As String = {"Sales", "Engineering"}
         Dim personalAvatars() As String = {"Heart", "Smile"}
         Dim workAvatars() As String = {"VIP", "Local", "Foreign"}
         
         
         If personalRadioButton.Checked = True Then
            BindDropDown(groupDropDown, personalGroups)
            BindDropDown(avatarDropDown, personalAvatars)
         Else
            BindDropDown(groupDropDown, workGroups)
            BindDropDown(avatarDropDown, workAvatars)
         End If
      End Sub 'BindGroupsAndAvatars
      
      
      Private Sub BindDropDown(dropDown As DropDownList, personalGroups() As String)
         dropDown.DataSource = personalGroups
         dropDown.DataBind()
      End Sub 'BindDropDown
      
      
      Private Sub workRadioButton_CheckedChanged(sender As Object, e As System.EventArgs) Handles workRadioButton.CheckedChanged
         BindGroupsAndAvatars()
      End Sub 'workRadioButton_CheckedChanged
      
      
      Private Sub cancelButton_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles cancelButton.Click
         ClearFields()
      End Sub 'cancelButton_Click
      
      
      Private Sub ClearFields()
         nameBox.Text = ""
         emailBox.Text = ""
      End Sub 'ClearFields
      
      
      Private Sub saveButton_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles saveButton.Click
         Dim type As String = "Personal"
         If workRadioButton.Checked = True Then
            type = "Work"
         End If 
         Dim name As String = nameBox.Text
         Dim email As String = emailBox.Text
         
         If name = String.Empty Then
            Return
         End If 
         Dim item As DataRow = FindRow(name, email)
         If item Is Nothing Then
            dataTable.Rows.Add(New Object() {name, email, type})
         Else
            item("Name") = name
            item("Email") = email
            item("Type") = type
         End If
         BindGrid()
         
         ClearFields()
      End Sub 'saveButton_Click
      
      
      Private Function FindRow(name As String, email As String) As DataRow
         Dim rows As DataRow() = dataTable.Select(String.Format("Name = '{0}' OR Email = '{1}'", name, email))
         If rows.Length > 0 Then
            Return rows(0)
         Else
            Return Nothing
         End If
      End Function 'FindRow
       
      Private Sub contactsGrid_DeleteCommand([source] As Object, e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles contactsGrid.DeleteCommand
         Dim row As DataRow = GetRow(e)
         row.Delete()
         
         BindGrid()
      End Sub 'contactsGrid_DeleteCommand
      
      
      Private Function GetRow(e As DataGridCommandEventArgs) As DataRow
         Dim index As Integer = e.Item.DataSetIndex
         Return dataView(index).Row
      End Function 'GetRow
      
      
      Private Sub contactsGrid_EditCommand([source] As Object, e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles contactsGrid.EditCommand
         Dim item As DataRow = GetRow(e)
         nameBox.Text = CStr(item("Name"))
         emailBox.Text = CStr(item("Email"))
         If CStr(item("Type")) = "Personal" Then
            personalRadioButton.Checked = True
         Else
            workRadioButton.Checked = True
         End If
         BindGroupsAndAvatars()
      End Sub 'contactsGrid_EditCommand
   End Class '_Default
End Namespace 'Telerik.CallbackExamplesVBNET.Callback.Examples.Demos.Contacts

⌨️ 快捷键说明

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