[英]Using DataPager with Repeater and SqlDataReader
Is it possible to have custom paging with Next and Prev and page numbers between them for Repeater
(like GridView
)? 是否可以通过Next和Prev进行自定义分页,并在
Repeater
之间进行页码设置(例如GridView
)? I found something but it works for 10 pages only. 我发现了一些东西,但仅适用于10页。 What I want is like this, something like google does for paging:
我想要的是这样的,类似Google的用于分页的内容:
< 1 2 3 4 ... 15 >
I found out extending Repeater
let me use DataPager, explained here: CodeProject: Extend Repeater to support DataPager
But when I use SqlDataReader
as DataSource
I face this error: 我发现扩展
Repeater
让我使用DataPager,在这里进行解释: CodeProject:扩展Repeater以支持DataPager
但是当我使用SqlDataReader
作为DataSource
,会遇到此错误:
Type 'System.Data.SqlClient.SqlDataReader' in Assembly
'System.Data, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' is not marked as serializable.
It's my code: 这是我的代码:
public bool ListBooksByCat(DataPagerRepeater.DataPagerRepeater repeater)
{
List<string> selection = new List<string>();
Dictionary<string, object> clause = new Dictionary<string, object>();
clause.Add("IsValid", true);
SqlDB myDb = new SqlDB(this.Connection);
try
{
SqlDataReader reader = myDb.Retrive(this.TableName, selection, clause, "bookid", true);
repeater.DataSource = reader;
repeater.DataBind();
reader.Close();
return true;
}
catch (Exception e)
{
//logging errors
return false;
}
}
Note
: DataPagerRepeater.DataPagerRepeater is built in linked article. Note
:DataPagerRepeater.DataPagerRepeater是在链接的文章中内置的。
Rather than binding to the SqlReader you should bind your control to DataTable or some other collection which take data offline(DataReader always remain in connected mode during binding). 而不是绑定到SqlReader,您应该将控件绑定到DataTable或其他一些使数据脱机的集合(在绑定过程中,DataReader始终处于连接模式)。 You're getting this error because the SqlDataReader is a resource related object and any resource-related object cannot be "passed" to a client.
由于SQLDataReader是与资源相关的对象,并且无法将任何与资源相关的对象“传递”给客户端,因此出现此错误。
I copied SqlDataReader
to a DataTable
then bind the repeater to it: 我将
SqlDataReader
复制到DataTable
然后将转发器绑定到它:
SqlDataReader reader = myDb.Retrive(this.TableName, selection, clause, "bookid", true);
DataTable dt = new DataTable();
dt.Load(reader);
reader.Close();
repeater.DataSource = dt;
repeater.DataBind();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.