使用ASP.NET 4.0在GridView中实现自定义分页 [英] Implement Custom Pagination in GridView with ASP.NET 4.0

查看:54
本文介绍了使用ASP.NET 4.0在GridView中实现自定义分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的aspx页面中有一个gridview,我想实现自定义分页来显示记录。

如何构建查询以根据页面大小和页面索引从数据库中获取数据。



在我的数据库表studentRecord中,id(identity(1,1)),studentName,RollNo,fathername,Class,MobileNo,Address



i希望将所有这些信息绑定到gridview

I have a gridview in my aspx page and i want to implement custom paging to display record.
how to build query to fatch data from database according to page size and page index.

In my database table studentRecord with id(identity (1,1)), studentName,RollNo,fathername,Class,MobileNo,Address

i want to bind all these info into gridview

推荐答案

请参考以下链接:

使用SQL Server存储过程在ASP.Net GridView中进行自定义分页 [ ^ ]

GridView DropDownList寻呼机 [ ^ ]

GridView自定义分页 [ ^ ]

您还可以查看:通过大量数据进行有效分页 [ ^ ]





希望它有所帮助!

- Amit
Refer the links below:
Custom Paging in ASP.Net GridView using SQL Server Stored Procedure[^]
GridView DropDownList Pager[^]
GridView Custom Paging[^]
You can also check : Efficiently Paging Through Large Amounts of Data[^]


Hope it helps!
--Amit


您必须在商店程序中传递所需的页面大小和页码



并修改此查询据你所知



You have to pass pagesize and page number that you want in store procedure

and modify this query according to you

CREATE PROC dbo.GetData( @PageSize int,@PageNumber int) as
begin
select * From
(
select RANK() over(order by ID) as RO_ID, * From dbo.StudentRecord
)a  where a.RO_ID between @PageSize*(@PageNumber-1) and @PageSize*(@PageNumber-1)+@PageSize
end


CREATE PROCEDURE dbo.usp_sel_AnyList
	@GroupID INT
	, @StartDate DATETIME
	, @EndDate DATETIME
	, @ZoneID INT
	, @ShowArchived BIT = 0
	, @DeliveryStatus INT = 0
	, @SortColumn VARCHAR(25) = ''
	, @SortOrder VARCHAR(4) = 'asc'
	, @StartIndex INT = 0
	, @Count INT
AS

BEGIN

	SET NOCOUNT ON

	DECLARE @EndIndex INT
	SET @EndIndex = @StartIndex + @Count - 1

	--If sort order is neither asc/desc set it to asc
	IF(@SortOrder <> 'desc')
	SET @SortOrder = 'asc'

	DECLARE @SortPattern VARCHAR(30)

	SET @SortOrder = LOWER(@SortOrder)
	SET @SortColumn = LOWER(@SortColumn)

	IF ( @SortColumn = '' )
	SET @SortColumn = 'default'

	SET @SortPattern = @SortColumn + '-' + @SortOrder

	SELECT DISTINCT * FROM (
		SELECT
				TotalRows = COUNT(*) OVER()
				, RowNumber = ROW_NUMBER() OVER
				( ORDER BY SiteId					 )
					, SiteId
					, SiteName
					, AdIDString
					, AdName
					, AdFileName
					, Text1
					, StartDate
					, EndDate
					, Days
					, AccountID
					, StatusID
					, DownloadDate
					, ZoneName
					, LoginID
					, SourceUrl
			FROM (
				SELECT
					o.SiteId
					, o.OrgName as SiteName
					, AdIDString = CAST(a.AdID AS VARCHAR(36))
					, a.Name AS AdName
					, af.FileName AS AdFileName
					, Text1 = ISNULL(CONVERT(VARCHAR(max),a.Text1),'')
					, a.StartDate
					, a.EndDate
					, a.Days
					, AccountID = CAST(a.AccountId AS VARCHAR(36))
					, mf.StatusID
					, DownloadDate = smf.TranDate
					, z.ZoneName
					, act.LoginID
					, mf.SourceUrl
				FROM dbo.Ads a (NOLOCK)
					JOIN (
						SELECT 
							AdID
							, ManifestFileID , FileName
						FROM dbo.AdFiles (NOLOCK)
						GROUP BY 
							AdID
							, ManifestFileID , FileName
						) af
						ON a.AdID = af.AdID
					JOIN Programming.dbo.SiteAds b (NOLOCK) ON a.AdID = b.AdId
					JOIN dbGamePlay..tbOrg o (NOLOCK) ON o.SiteId = b.SiteId 
					JOIN GameManagement..GroupSites gs (NOLOCK) ON gs.SiteID = b.SiteID AND gs.GroupID= @GroupID
					JOIN Accounts act (NOLOCK) ON a.AccountID = act.AccountID
					LEFT JOIN Programming.dbo.AdBackgrounds ab (NOLOCK) ON ab.AdBackgroundID = a.AdBackgroundID
					LEFT JOIN Programming.dbo.ManifestFile mf (NOLOCK) ON mf.ManifestFileID = af.ManifestFileID 
					LEFT JOIN Programming.dbo.SiteManifestFile smf (NOLOCK) ON smf.ManifestFileID = af.ManifestFileID 
						AND smf.SiteID = b.SiteID
					LEFT JOIN Programming.dbo.Zone z (NOLOCK)ON a.ZoneID = z.ZoneID
				WHERE (@StartDate <= a.EndDate OR EndDate IS NULL)
					AND (@EndDate >= StartDate OR StartDate IS NULL)
					AND (@ZoneID = 0 OR a.ZoneID = @ZoneID)
					AND ((@ShowArchived = 0 AND (a.EndDate >= GETDATE() OR a.EndDate IS NULL)) OR (@ShowArchived = 1))
					AND ( @DeliveryStatus = 0 ) 
						OR 
						( @DeliveryStatus = 1 AND smf.TranDate IS NOT NULL )
						 OR 
						( @DeliveryStatus = 2 AND smf.TranDate IS NULL )
				) adFiles
		) t
	WHERE @startIndex = -1
	OR RowNumber BETWEEN @startIndex AND @EndIndex
	ORDER BY RowNumber
END

这篇关于使用ASP.NET 4.0在GridView中实现自定义分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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