DataGrid分页时出现错误!在线等....

netWild 2005-05-12 10:35:33
练习用DataGrid的内置分页功能,数据源是DataReader

错误描述如下:
========================================
异常详细信息: System.Web.HttpException: 类型“DataGridLinkButton”的控件“indexList__ctl7__ctl1”必须放在具有 runat=server 的窗体标记内。
========================================

代码如下:
========================================
<%@ page language="vb" %>
<%@ import namespace="System.Configuration" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.Oledb" %>
<script runat=server>
Public s01 as new String("hello!")
sub page_load(src as Object,e as EventArgs)
if not page.isPostBack then
doList()
end if
end sub
sub doList()
Dim dbstr as String=ConfigurationSettings.AppSettings("dbstr")
Dim myConn as OledbConnection=new OledbConnection(dbstr)
myConn.open()
Dim SQLstr as String
SQLstr="select txtId,userId,userName,txtTitle,txtTime,isTop,clickNum,followCount,lastTime,relUserId,relUserName from v_indexList order by isTop Desc,lastTime Desc"
Dim myCmd as OledbCommand=new OledbCommand(SQLstr,myConn)
Dim myReader as OledbDataReader=myCmd.executeReader()
indexList.DataSource=myReader
indexList.DataBind()
myConn.close()
end sub
protected sub PageIndexChanged_OnClick(Sender as Object,E as DataGridPageChangedEventArgs)
indexList.CurrentPageIndex=E.NewPageIndex
doList()
end sub
protected function getIsTop(ist as Integer,followC as Integer) as String
if ist=1 then
return "<center><img src=images/top.gif></center>"
elseif followC>10 then
return "<center><img src=images/hot.gif></center>"
else
return "<center><img src=images/old.gif></center>"
end if
end function
protected function getTTclass(isto as Integer) as String
if isto=0 then
return " class=i"
else
return " "
end if
end function
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Author" contect="网无忌 Tel:13704996043;Email:zmy@ecolor99.com;http://www.ecolor99.com">
<title>netWild ASP.net讨论板</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div align=center>
<!--#include file=menu.aspx-->
<br>
<asp:DataGrid id=indexList runat=server width=95%
cellspacing=0
cellpadding=4
BorderColor="#DDDDDD"
HeaderStyle-CssClass="tableHeader"
ItemStyle-CssClass="tableItem"
GridLines=both
AllowPaging=true
PageSize=3>
</asp:DataGrid>
<br>
</div>
</body>
</html>
========================================

在线等待答复!解决就给分


...全文
98 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hchxxzx 2005-05-13
  • 打赏
  • 举报
回复
这提示不是写得很清楚吗?
AllowPaging = true;
AllowCustomPaging = true;

你右键点击此控件,到它的"属性生成器"里面看一下,有选项.
netWild 2005-05-12
  • 打赏
  • 举报
回复
好了,谢谢smx717616()

加了form后,把数据源改成DataSet就成功了

如果数据源用DataReader出现错误:
System.Web.HttpException: 当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 indexList 的 DataGrid 必须设置 VirtualItemCount。


这是为什么?难道DataReader不支持分页吗?
smx717616 2005-05-12
  • 打赏
  • 举报
回复
把你的 WebGrid 放在
<form id="Form1" method="post" runat="server">
</form>
里看看。
yilan505 2005-05-12
  • 打赏
  • 举报
回复
indexList__ctl7__ctl1

这个东东在哪里??我怎么没找到??

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧