分页-使用用户选择的页码显示sql中的数据 [英] Paging- show the data from sql with page number selected by user

查看:45
本文介绍了分页-使用用户选择的页码显示sql中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网格"视图中,从sql数据库中选择了100条记录.
现在,我只想在一页上显示10条记录.
我想在上一个或下一个显示下10条记录
或者在页面末尾,我将数字从1切换为10,然后单击该数字,以显示受尊重的10条记录.
请建议我最简单的方法

in Grid view there are 100 records selected from sql database.
Now i want to show the only 10 records on one page.
On prev or next i want to show the next 10 records
OR in end of the page i shwo the numbers from 1 to 10 and on click of that number i want to show the respected 10 records.
please suggest me simplest way to do this

推荐答案

尝试
ASP.NET中的数据分页 [有效地分页处理大量数据[ ^ ]
Try
Data Paging in ASP.NET[^]
Efficiently Paging Through Large Amounts of Data[^]


SQL Server 2005分页结果 [ ^ ]


Lets read the following.

Right click on Gridview choose properties in properties windows 
set allowpaging =true.

set pageSize=10 or any number.


''This is GridView1_PageIndexChanging event where you set the current page index.

 Protected Sub GridView1_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        DisplayData()''this is procedure which display data in gridview. Whenever you click on page number it calls this procedure.
End Sub



Private Sub DisplayData()
        Dim cmd As New SqlCommand("select * from mstEmployee order by EmpCode", con)
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        ''Dim dr As SqlDataReader '' dont use datareader because paging doesnot work with data reader
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter
        da.SelectCommand = cmd
        da.Fill(ds, 0)
        If ds.Tables(0).Rows.Count > 0 Then
            GridView1.DataSource = ds
            GridView1.DataBind()
        End If
        ''dr = cmd.ExecuteReader
        con.Close()
   
End Sub


这篇关于分页-使用用户选择的页码显示sql中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆