练习用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:[email protected];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>
========================================在线等待答复!解决就给分

解决方案 »

  1.   

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

  2.   

    把你的 WebGrid 放在 
    <form id="Form1" method="post" runat="server">
    </form>
    里看看。
      

  3.   

    好了,谢谢smx717616()加了form后,把数据源改成DataSet就成功了如果数据源用DataReader出现错误:
    System.Web.HttpException: 当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 indexList 的 DataGrid 必须设置 VirtualItemCount。
    这是为什么?难道DataReader不支持分页吗?
      

  4.   

    这提示不是写得很清楚吗?
    AllowPaging = true;
    AllowCustomPaging = true;你右键点击此控件,到它的"属性生成器"里面看一下,有选项.