现在的位置: 首页 > 综合 > 正文

Socut.Data 与 ASPNetPager的结合使用

2013年11月23日 ⁄ 综合 ⁄ 共 848字 ⁄ 字号 评论关闭

1,首先在web.config设置

<appSettings>
  <add key="SocutDataLink" value="server=.;database=MyBookShop;uid=sa;pwd=hxhlxf;"/>
    </appSettings>

2,在页面拉入GridView与ASPNetPager控件(通过工具箱引用)

     写入代码:

     protected void Page_Load(object sender, EventArgs e)
    {
        AspNetPager1.RecordCount = Convert.ToInt32(Socut.Data.ExecuteScalar("select count(*) from books"));
        Bind();
    }

    public void Bind()
    {
        DataSet ds = Socut.Data.ExecuteDataSet("select id,title from books",//指定sql语句
                                               AspNetPager1.PageSize*(AspNetPager1.CurrentPageIndex-1),//指定从那条开始查询
                                               AspNetPager1.PageSize);//查询多少条
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }

 

3、记得把AlwaysShow属性设为true、以为默认清空AspNetPager控件是隐藏的

抱歉!评论已关闭.