0

Is it possible to have custom paging with Next and Prev and page numbers between them for Repeater (like GridView)? I found something but it works for 10 pages only. What I want is like this, something like google does for paging:

< 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:

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.

4

2 回答 2

0

我复制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();
于 2013-08-11T14:35:07.323 回答
0

而不是绑定到 SqlReader,您应该将控件绑定到 DataTable 或其他一些使数据脱机的集合(DataReader 在绑定期间始终保持连接模式)。您收到此错误是因为 SqlDataReader 是与资源相关的对象,并且任何与资源相关的对象都不能“传递”给客户端。

于 2013-08-11T12:29:53.883 回答