table.ascx

来自「《精通ASP.NET网络编程》附带实例」· ASCX 代码 · 共 41 行

ASCX
41
字号
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
<script language="VB" runat="server">
   Public Database As String
   Public Table As String
   Dim startIndex As Integer
   Function CreateDataView() As DataView
      Dim Provider, SQL, ConnStr As String
      Provider = "Microsoft.Jet.OLEDB.4.0;"
      ConnStr = "Provider="+Provider+"Data Source="+Server.MapPath(Database)
      Dim Cmd As OleDbDataAdapter
      SQL = "Select * From " & Table
      Cmd = New OleDbDataAdapter(SQL, ConnStr)
      Dim ds As DataSet = new DataSet()
      Cmd.Fill(ds, Table)
      CreateDataView = new DataView(ds.Tables(Table))
   End Function
   Sub Page_Load(sender As Object, e As EventArgs) 
      Grid1.DataSource = CreateDataView()
      Grid1.DataBind()
   End Sub
   Sub ChangePage(sender As Object, e As DataGridPageChangedEventArgs)
      startIndex = e.NewPageIndex*Grid1.PageSize
      Grid1.CurrentPageIndex = e.NewPageIndex
      Grid1.DataSource = CreateDataView()
      Grid1.DataBind()
   End Sub
</script>
<asp:DataGrid 
    AllowPaging="True"
    PageSize="4"
    PagerStyle-Mode="NumericPages"
    PagerStyle-HorizontalAlign="Right"
    OnPageIndexChanged="ChangePage"
    HeaderStyle-BackColor="#AAAADD" 
    AlternatingItemStyle-BackColor="#FFFFC0"
    BorderColor="Black"
    CellPadding="2" 
    CellSpacing="0"
    id="Grid1" 
    runat="server"/>

⌨️ 快捷键说明

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