ArcEngine , VS.NET , SQLSERVER
淡泊明智,宁静致远~~~
AspNetPager作为分页工具,常常用于绑定数据控件,如DataGrid , Repeater等
在这里,简单讲解下 绑定 Repeater 控件的方法,其余控件绑定方法类似:

    '全局变量 i 用于 读取 数据集记录的条数(注意:读取一次就够了)
    Dim i As New Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If i = 0 Then
            con = New SqlConnection(ConfigurationManager.ConnectionStrings("NEWS_ConnectionString").ConnectionString)
            con.Open()
            cmd = New SqlCommand()
            cmd.Connection = con
            cmd.CommandText = "select count(*) from XWNRB "

            'AspNetPager控件 可见
            Me.AspNetPager1.Visible = True

            'AspNetPager控件 每页显示大小为10条记录
            Me.AspNetPager1.PageSize = 10

            'AspNetPager控件 记录总的记录条数
            Me.AspNetPager1.RecordCount = Convert.ToInt32(cmd.ExecuteScalar())

            'AspNetPager控件 数据绑定
            Me.SHOW_DATA_LIST()
            i = i + 1
            con.Close()
        End If

    End Sub

    Protected Sub SHOW_DATA_LIST()

        con = New SqlConnection(ConfigurationManager.ConnectionStrings("NEWS_ConnectionString").ConnectionString)
        sql_Text = "select * from XWNRB where "
        da = New SqlDataAdapter(sql_Text, con)
        Dim ds As New Data.DataSet

        '第一个参数为存储入的数据集为ds  
        '第二个参数为存储的起始记录序号
        '第三个参数为存储的记录每页条数
        '第四个参数为存储入的数据集ds中的具体某个表
        da.Fill(ds, Me.AspNetPager1.PageSize * (Me.AspNetPager1.CurrentPageIndex - 1), Me.AspNetPager1.PageSize, "NEWS_LIST")

        '真正绑定
        Me.Repeater2.DataSource = ds.Tables("NEWS_LIST").DefaultView
        Me.Repeater2.DataBind()

    End Sub

    '即每次点击新的页面,或者点击 Pre,Next,Last.....时候都会触发这个事件
    Protected Sub AspNetPager1_PageChanged(ByVal src As Object, ByVal e As Wuqi.Webdiyer.PageChangedEventArgs) Handles AspNetPager1.PageChanged
        
        '更新当前所在的页数序列
        Me.AspNetPager1.CurrentPageIndex = e.NewPageIndex
        '更新完后绑定
        Me.SHOW_DATA_LIST()

    End Sub

posted on 2008-07-13 10:21  peaceful_fish  阅读(1036)  评论(2编辑  收藏  举报