ASPNET:DataGrid+存储过程的分页编辑代码[原创]-.Net技术-3P代码网
繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> ASPNET:DataGrid+存储过程的分页编辑代码[原创]

ASPNET:DataGrid+存储过程的分页编辑代码[原创]

2007-02-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介: Dim conNorthwind As SqlConnection Dim strSql As String Dim strSelect As String Dim intStartIndex As Integer Dim intEndIndex As Integer Dim intRecordCount As Integer Dim cmdSql As SqlCommand Sub...

<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Import Namespace="System.Data" %>

DataGridCustomPaging.aspx

ID="dgrdProducts"

OnEditCommand="dgrdProducts_EditCommand"

OnUpdateCommand="dgrdProducts_UpdateCommand"

OnCancelCommand="dgrdProducts_CancelCommand"

DataKeyField="A_ArticleID"

AutoGenerateColumns="false"

showheader="true"

AllowPaging="True"

AllowCustomPaging="True"

HeaderStyle-BackColor="Salmon"

PageSize="10"

OnPageIndexChanged="dgrdProducts_PageIndexChanged"

PagerStyle-Mode="NumericPages"

AlternatingItemStyle-BackColor="#eeaaee"

Font-Size="10pt"

Font-Name="Verdana"

CellSpacing="0"

CellPadding="3"

GridLines="Both"

BorderWidth="1"

BorderColor="black"

PagerStyle-HorizontalAlign="Right">

HeaderText="序列号"

DataField="ArticleID"

ReadOnly="True" />

HeaderText="标题"

DataField="Topic" />

HeaderText="编辑者"

DataField="Editor" />

EditText="Edit!"

UpdateText="Update!"

CancelText="Cancel!" />

HeaderText="编辑"

DataNavigateUrlField="ArticleID"

DataNavigateUrlFormatString="Details.aspx?id={0}"

Text="编辑"/>

下面是存储过程:

CREATE PROCEDURE newsPaged

(

@PageIndex int,

@PageSize int

)

AS

BEGIN

DECLARE @PageLowerBound int

DECLARE @PageUpperBound int

DECLARE @RowsToReturn int

-- First set the rowcount

SET @RowsToReturn = @PageSize * (@PageIndex + 1)

SET ROWCOUNT @RowsToReturn

-- Set the page bounds

SET @PageLowerBound = @PageSize * @PageIndex

SET @PageUpperBound = @PageLowerBound + @PageSize + 1

-- Create a temp table to store the select results

CREATE TABLE #PageIndex

(

IndexId int IDENTITY (1, 1) NOT NULL,

ArticleID int,

)

-- Insert into the temp table

INSERT INTO #PageIndex (ArticleID)

SELECT

ArticleID

FROM

tablename

ORDER BY

ArticleID DESC

-- Return total count

SELECT COUNT(ArticleID) FROM tablename

-- Return paged results

SELECT

O.ArticleID,O.Topic,Editor

FROM

tablename O,

#PageIndex PageIndex

WHERE

O.ArticleID = PageIndex.ArticleID AND

PageIndex.IndexID > @PageLowerBound AND

PageIndex.IndexID < @PageUpperBound

ORDER BY

PageIndex.IndexID

END

责任编辑:admin
相关文章