练习用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>
========================================在线等待答复!解决就给分
========================================
异常详细信息: 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>
========================================在线等待答复!解决就给分
解决方案 »
- 在线等待! .net问题
- cookies 问题
- AspNetPager分页控件怎么去写成Page_Load绑定 求解
- vs2005中,刚拖出来的按钮总是很长,请大家帮忙,详细点 我是初学者,谢啦
- |M| 如何正确的给一段画出来的文本换行
- .net下有什么组件可以生成静态html页面吗?
- 用户控件中动态生成 HtmlInputCheckBox 怎样让 name 一样
- 怎么对实现ITemplate的类里的控件进行数据邦定?
- 动态更新问题
- 为什么在.aspx.vb中写的代码,能够执行呢?
- datalist响应编辑事件时怎么取表格里被点击的那一行某个单元格里的内容?
- 问题急,再问一次,在线等。这次给分100。在win2003中连接mssql的问题。
<form id="Form1" method="post" runat="server">
</form>
里看看。
System.Web.HttpException: 当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 indexList 的 DataGrid 必须设置 VirtualItemCount。
这是为什么?难道DataReader不支持分页吗?
AllowPaging = true;
AllowCustomPaging = true;你右键点击此控件,到它的"属性生成器"里面看一下,有选项.