首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 操作系统-> Windows 2003教程
ASPNET:DataGrid+存储过程的分页编辑代码[原创]-.NET教程,Asp.Net开发
作者:网友供稿 点击:27
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
 

<%@ import namespace="system.data.sqlclient" %>
<%@ import namespace="system.data" %>

<script runat="server">

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 page_load
  btnfirst.text = "首页"
  btnprev.text = "上一页"
  btnnext.text = "下一页"
  btnlast.text = "末页"
  connorthwind = new sqlconnection( "server=192.168.4.1;uid=sa;pwd=111111;database=yourdbname" )
  if not ispostback then
    binddatagrid
  end if
end sub

sub binddatagrid
  dim cmdselect as sqlcommand
  dim dtrrecordcount as sqldatareader

  intendindex = dgrdproducts.pagesize
  cmdselect = new sqlcommand( "newspaged", connorthwind )
  cmdselect.commandtype = commandtype.storedprocedure
  cmdselect.parameters.add( "@pageindex", intstartindex )
  cmdselect.parameters.add( "@pagesize ", intendindex )
  connorthwind.open()
  dtrrecordcount = cmdselect.executereader()
  while dtrrecordcount.read()
    intrecordcount=dtrrecordcount(0)
  end while
  dgrdproducts.virtualitemcount = (intrecordcount / dgrdproducts.pagesize)
  dtrrecordcount.nextresult()
  dgrdproducts.datasource = dtrrecordcount
  dgrdproducts.databind()
  connorthwind.close()
end sub

sub dgrdproducts_pageindexchanged( s as object, e as datagridpagechangedeventargs )
  intstartindex = e.newpageindex
  dgrdproducts.currentpageindex = e.newpageindex
  binddatagrid
end sub
sub pagerbuttonclick(byval sender as object, byval e as eventargs)
  dim arg as string = sender.commandargument
  select case arg
      case "next"
        if (dgrdproducts.currentpageindex < (dgrdproducts.pagecount - 1)) then
           dgrdproducts.currentpageindex += 1
        end if
      case "prev"
        if (dgrdproducts.currentpageindex > 0) then
           dgrdproducts.currentpageindex -= 1
        end if
      case "last"
           dgrdproducts.currentpageindex = (dgrdproducts.pagecount - 1)
      case else
        page number
        dgrdproducts.currentpageindex = system.convert.toint32(arg)
  end select
  intstartindex=dgrdproducts.currentpageindex
  binddatagrid
end sub

sub dgrdproducts_editcommand( s as object, e as datagridcommandeventargs )
  dgrdproducts.edititemindex = e.item.itemindex
  intstartindex = dgrdproducts.currentpageindex
  binddatagrid
end sub

sub dgrdproducts_updatecommand( s as object, e as datagridcommandeventargs )
  dim intarticleid as integer
  dim txttopic as textbox
  dim txteditor as textbox
  dim strtopic as string
  dim streditor as string

  intarticleid = dgrdproducts.datakeys( e.item.itemindex )
  txttopic = e.item.cells( 1 ).controls( 0 )
  txteditor = e.item.cells( 2 ).controls( 0 )
  strtopic = txttopic.text
  streditor = txteditor.text
  strsql = "update tb_article set topic=@topic, " _
   & "editor=@editor where articleid=@articleid"
  cmdsql = new sqlcommand( strsql, connorthwind )
  cmdsql.parameters.add( "@topic", strtopic )
  cmdsql.parameters.add( "@editor", streditor )
  cmdsql.parameters.add( "@articleid", intarticleid )
  connorthwind.open()
  cmdsql.executenonquery()
  connorthwind.close()
  dgrdproducts.edititemindex = -1
  binddatagrid
end sub

sub dgrdproducts_cancelcommand( s as object, e as datagridcommandeventargs )
  dgrdproducts.edititemindex = -1
  binddatagrid
end sub
</script>

<html>
<head><title>datagridcustompaging.aspx</title></head>
<body>
<form runat="server">

<asp:datagrid runat="server"
  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">
  <alternatingitemstyle backcolor="#eeeeee"></alternatingitemstyle>
  <columns>
    <asp:boundcolumn
      headertext="序列号"
      datafield="articleid"
      readonly="true" />
    <asp:boundcolumn
      headertext="标题"
      datafield="topic" />
    <asp:boundcolumn
      headertext="编辑者"
      datafield="editor" />
    <asp:editcommandcolumn
      edittext="edit!"
      updatetext="update!"
      canceltext="cancel!" />
 <asp:hyperlinkcolumn
   headertext="编辑"
   datanavigateurlfield="articleid"
   datanavigateurlformatstring="details.aspx?id={0}"
   text="编辑"/>
  </columns>
</asp:datagrid>
<asp:linkbutton id="btnfirst" onclick="pagerbuttonclick" runat="server" font-name="verdana" font-size="8pt" forecolor="navy" commandargument="0"></asp:linkbutton>&nbsp;
<asp:linkbutton id="btnprev" onclick="pagerbuttonclick" runat="server" font-name="verdana" font-size="8pt" forecolor="navy" commandargument="prev"></asp:linkbutton>&nbsp;
<asp:linkbutton id="btnnext" onclick="pagerbuttonclick" runat="server" font-name="verdana" font-size="8pt" forecolor="navy" commandargument="next"></asp:linkbutton>&nbsp;
<asp:linkbutton id="btnlast" onclick="pagerbuttonclick" runat="server" font-name="verdana" font-size="8pt" forecolor="navy" commandargument="last"></asp:linkbutton>
</form>
</html>
下面是存储过程:
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


文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·c#自定义控件开发实例(1)-.NET教程,C#语言
·为DataGrid添加CheckBox控件-.NET教程,组件控件开发
·windows 2003 64位正式版抢先体验
·显示你个性的鼠标指针-网页设计,HTML/CSS
·水晶报表中子报表的数据绑定问题-.NET教程,报表/图形/Office
·windows 2003组策略和安全模板的应用
·快速关闭windows 2003的三种方法
·数据库设计范式(实例)-数据库专栏,SQL Server
·windows 2003服务器防止海洋木马的安全设置
·《用C#和数据库实现无限级分类法》修正程序-.NET教程,C#语言
最新文章
·对.net framework 反射的反思_asp.net技巧
·google工具条要跟pagerank说再见?_google推广
·windows vista为什么不允许两个用户同时登录_windows vista
·田锋林:seo博客细节调整_seo网站优化
·将ssh与php相连接 确保传输数据的安全_php技巧
·photoshop照片合成实例:添加烟花_photoshop教程
·深入了解flash as中的setinterval方法_flash教程
·feedburner的rss广告收益分析_网赚技巧
·如何允许google的抓取工具访问我的需要登录的网页_网赚技巧
·王通:adsense出现的一些严重问题_网赚技巧
相关主题
  • aspnetpager分页控件--使用方法_asp.net技巧
  • aspnet_wp.exe could not be started_asp.net技巧
  • aspnetforums的数据层概述_asp.net技巧
  • AspNetForums的数据层概述-.NET教程,数据库应用
  • aspnetforums 代码中的web设计模式-ASP教程,ASP应用
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭