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

📄 superdatagrid.vb

📁 asp.net技术内幕的书配源码
💻 VB
📖 第 1 页 / 共 3 页
字号:

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing


Namespace Superexpert


'*********************************************************************
'
' SuperDataGrid Class
'
' The SuperDataGrid control supports sorting, paging, editing, 
' and deleting records through its
' EnableSorting, EnablePaging, EnableEditing, and EnableDeleting 
' properties.
'
' See the SuperDataGridCS.aspx or SuperDataGridVB.aspx files for
' samples of using this control.
'
' This control is from the book ASP.NET Unleashed written by 
' Stephhen Walther and published by SAMS publishing.
'
'*********************************************************************

Public Class SuperDataGrid
    Inherits WebControl
    Implements IPostBackDataHandler, IPostBackEventHandler 
    
    Private _enableSorting As Boolean = True
    Private _enableEditing As Boolean = True
    Private _enableDeleting As Boolean = True
    Private _enablePaging As Boolean = True
    
    Private _dataGridData As New DataTable()
    Private _dataGridView As New DataView()
    Private _dataGridSchema As New DataTable()
    Private colEditValues As New Hashtable()
    
    Private _editClicked As Boolean = False
    Private _updateClicked As Boolean = False
    Private _deleteClicked As Boolean = False
    Private _deleteItemIndex As Integer = - 1
    
    Private _tableStyle As New TableStyle()
    Private _headerStyle As New TableItemStyle()
    Private _itemStyle As New TableItemStyle()
    Private _alternatingItemStyle As New TableItemStyle()
    Private _pagerStyle As New TableItemStyle()
    
    Private _commandText As String = String.Empty
    Private _pageSize As Integer = 10
    Private _prevText As String = "<"
    Private _nextText As String = ">"
    Private _pagerText As String = "Page {0} of {1}"
    
    Private _errorMessage As String = String.Empty
    
    
    '*********************************************************************
    '
    ' ConnectionString Property
    '
    ' The Connection String for the database. Notice that this must
    ' be a valid SQL connection string since the SuperDataGrid uses
    ' the SqlClient classes.
    '
    '*********************************************************************
    
    Public Property ConnectionString() As String
        Get
            If ViewState("ConnectionString") Is Nothing Then
                Return String.Empty
            Else
                Return CStr(ViewState("ConnectionString"))
            End If
        End Get
        Set
            ViewState("ConnectionString") = value
        End Set
    End Property 
    
    
    '*********************************************************************
    '
    ' TableName Property
    '
    ' The name of the database table to retrieve the data from. Instead
    ' of using this property, you can use the CommandText property and
    ' specify your own SELECT statement (with parameters).
    '
    '*********************************************************************
    
    Public Property TableName() As String
        Get
            If ViewState("TableName") Is Nothing Then
                Return String.Empty
            Else
                Return CStr(ViewState("TableName"))
            End If
        End Get
        Set
            ViewState("TableName") = value
        End Set
    End Property 
    
    
    '*********************************************************************
    '
    ' CommandText Property
    '
    ' The CommandText property enables you to specify a SELECT statement
    ' to use when retrieving database data.
    '
    '*********************************************************************
    
    Public Property CommandText() As String
        Get
            If ViewState("CommandText") Is Nothing Then
                Return String.Empty
            Else
                Return CStr(ViewState("CommandText"))
            End If
        End Get
        Set
            ViewState("CommandText") = value
        End Set
    End Property 
    
    '*********************************************************************
    '
    ' TableStyle Property
    '
    ' The TableStyle object applied to the SuperDataGrid table. Use
    ' this property to control the formatting of the main table.
    '
    '*********************************************************************
    
    Public ReadOnly Property TableStyle() As TableStyle
        Get
            Return _tableStyle
        End Get
    End Property 
    
    
    '*********************************************************************
    '
    ' HeaderStyle Property
    '
    ' Use this property to control the formatting of the Header row.
    '
    '*********************************************************************
    
    Public ReadOnly Property HeaderStyle() As TableItemStyle
        Get
            Return _headerStyle
        End Get
    End Property 
    
    
    '*********************************************************************
    '
    ' ItemStyle Property
    '
    ' Use this property to control the formatting of each row.
    '
    '*********************************************************************
    
    Public ReadOnly Property ItemStyle() As TableItemStyle
        Get
            Return _itemStyle
        End Get
    End Property 
    
    
    '*********************************************************************
    '
    ' AlternatingItemStyle Property
    '
    ' Use this property to control the formatting of every other row.
    '
    '*********************************************************************
    
    Public ReadOnly Property AlternatingItemStyle() As TableItemStyle
        Get
            Return _alternatingItemStyle
        End Get
    End Property 
    
    
    '*********************************************************************
    '
    ' PagerStyle Property
    '
    ' Use this property to control the formatting of the pager row.
    '
    '*********************************************************************
    
    Public ReadOnly Property PagerStyle() As TableItemStyle
        Get
            Return _pagerStyle
        End Get
    End Property 
    
    '*********************************************************************
    '
    ' SortColumn Property
    '
    ' The column to sort on.
    '
    '*********************************************************************
    
    Public Property SortColumn() As String
        Get
            If ViewState("SortColumn") Is Nothing Then
                Return String.Empty
            Else
                Return CStr(ViewState("SortColumn"))
            End If
        End Get
        Set
            ViewState("SortColumn") = value
        End Set
    End Property 
    
    
    '*********************************************************************
    '
    ' SortOrder Property
    '
    ' The Order to sort by (for example, ASC or DESC).
    '
    '*********************************************************************
    
    Public Property SortOrder() As String
        Get
            If ViewState("SortOrder") Is Nothing Then
                Return "ASC"
            Else
                Return CStr(ViewState("SortOrder"))
            End If
        End Get
        Set
            ViewState("SortOrder") = value
        End Set
    End Property 
    
    
    '*********************************************************************
    '
    ' CurrentPageIndex Property
    '
    ' The current page of records to display.
    '
    '*********************************************************************
    
    Public Property CurrentPageIndex() As Integer
        Get
            If ViewState("CurrentPageIndex") Is Nothing Then
                Return 1
            Else
                Return ViewState("CurrentPageIndex")
            End If
        End Get
        Set
            ViewState("CurrentPageIndex") = value
        End Set
    End Property 
    
    
    '*********************************************************************
    '
    ' EnableSorting Property
    '
    ' When true, columns can be sorted.
    '
    '*********************************************************************
    
    Public Property EnableSorting() As Boolean
        Get
            Return _enableSorting
        End Get
        Set
            _enableSorting = value
        End Set
    End Property 
    
    
    
    '*********************************************************************
    '
    ' EnableEditing Property
    '
    ' When true, rows can be edited.
    '
    '*********************************************************************
    
    Public Property EnableEditing() As Boolean
        Get
            Return _enableEditing
        End Get
        Set
            _enableEditing = value
        End Set
    End Property 
    
    '*********************************************************************
    '
    ' EnableDeleting Property
    '
    ' When true, rows can be deleted.
    '
    '*********************************************************************
    
    Public Property EnableDeleting() As Boolean
        Get
            Return _enableDeleting
        End Get
        Set
            _enableDeleting = value
        End Set
    End Property 
    
    
    
    '*********************************************************************
    '
    ' PageSize Property
    '
    ' The number of rows to display per page when paging is enabled.
    '
    '*********************************************************************
    
    Public Property PageSize() As Integer
        Get
            Return _pageSize
        End Get
        Set
            _pageSize = value
        End Set
    End Property 
    
    
    '*********************************************************************
    '
    ' EditItemIndex Property
    '
    ' The current row selected for editing.
    '
    '*********************************************************************
    
    Public Property EditItemIndex() As Integer
        Get
            If ViewState("EditItemIndex") Is Nothing Then
                Return - 1
            Else
                Return ViewState("EditItemIndex")
            End If
        End Get
        Set
            ViewState("EditItemIndex") = value
        End Set
    End Property
     
    
    
    '*********************************************************************
    '
    ' LoadPostData Method
    '
    ' When editing is enabled, and data is submitted, this method
    ' updates the data stored in the colEditValues collection.

⌨️ 快捷键说明

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