how did you bind the data? post your code or play with
<%@Import Namespace="system.data"%>
<%@Import Namespace="system.data.sqlclient"%>
<html>
<form runat="server">
<asp:datagrid id="dg" runat="server" allowpaging="true" pagesize="5" autogeneratecolumns="true"
onpageindexchanged="pagechanged"
AllowCustomPaging="true"
PagerStyle-Mode="NumericPages"
/>
</form>
</html>
<script language="vb" runat="server">
dim strconn as string="server=localhost;database=northwind;uid=sa;password=;"
Sub SetItemCount()
dim conn as new sqlconnection(strconn)
conn.open
dim strsql as string="select count(*) from customers"
dim cmd as new sqlcommand(strsql,conn)
dg.VirtualItemCount = cmd.ExecuteScalar()
conn.close
end Sub sub binddata(nPage as Integer)
dim nTopCount as Integer = (nPage+1) * dg.PageSize dim conn as new sqlconnection(strconn)
conn.open
dim strsql as string= "select * from (select top " & dg.PageSize & " * from ( select top " & nTopCount & " * from customers order by CustomerID ) t order by CustomerID desc) t2 order by CustomerID"
dim cmd as new sqlcommand(strsql,conn)
dg.datasource=cmd.executereader()
dg.databind()
conn.close
end sub Sub page_load(sender as object,e as eventargs)
if not ispostback then
SetItemCount()
binddata(0)
end if
End sub
Sub pagechanged(sender as object,e as datagridpagechangedeventargs)
dg.currentpageindex=e.newpageindex
binddata(dg.currentpageindex)
End sub
</script>
<%@Import Namespace="system.data"%>
<%@Import Namespace="system.data.sqlclient"%>
<html>
<form runat="server">
<asp:datagrid id="dg" runat="server" allowpaging="true" pagesize="5" autogeneratecolumns="true"
onpageindexchanged="pagechanged"
AllowCustomPaging="true"
PagerStyle-Mode="NumericPages"
/>
</form>
</html>
<script language="vb" runat="server">
dim strconn as string="server=localhost;database=northwind;uid=sa;password=;"
Sub SetItemCount()
dim conn as new sqlconnection(strconn)
conn.open
dim strsql as string="select count(*) from customers"
dim cmd as new sqlcommand(strsql,conn)
dg.VirtualItemCount = cmd.ExecuteScalar()
conn.close
end Sub sub binddata(nPage as Integer)
dim nTopCount as Integer = (nPage+1) * dg.PageSize dim conn as new sqlconnection(strconn)
conn.open
dim strsql as string= "select * from (select top " & dg.PageSize & " * from ( select top " & nTopCount & " * from customers order by CustomerID ) t order by CustomerID desc) t2 order by CustomerID"
dim cmd as new sqlcommand(strsql,conn)
dg.datasource=cmd.executereader()
dg.databind()
conn.close
end sub Sub page_load(sender as object,e as eventargs)
if not ispostback then
SetItemCount()
binddata(0)
end if
End sub
Sub pagechanged(sender as object,e as datagridpagechangedeventargs)
dg.currentpageindex=e.newpageindex
binddata(dg.currentpageindex)
End sub
</script>
解决方案 »
- 求大家救救我这个linux C程序员 .net oledb excel conn.open问题
- IIS中向其它机器上传文件,提示 System.IO.IOException: 登录失败: 未知的用户名或错误密码。
- 关于aspx页面生成excel报表后,系统进程不能释放的问题
- 请问如何在事件中引用aspx页面repeater控件所包含控件的数据
- 请教,这个错误提示啥意思?
- Visual C#.NET交流群
- Cookie访问问题(有点怪)
- 如何取得iframe里面的内容,需跨域。
- sql语句中,这样判断字段TypeID是不是在一个Array里呢?还有Array和ArrayList有何不同?
- 邮件分页问题。假设有20封邮件,想每页显示5封,应该怎么做?
- 在网页中提供文件上传
- 快救救我们吧!!!!!!!!!! 我又受不了了
谢了,saucer!