分享

Repeater 控件 + 分页控件的使用

 昵称10504424 2013-07-15

前台页面 A.aspx:

 

 

 

=============================

后台代码 A.aspx.cs:

 

public partial class ConventionList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindToDataList();
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindToDataList();
    }
 
    private void BindToDataList()
    {
        int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
        int pageSize = 5;
        this.AspNetPager1.PageSize = pageSize;
        int firstPage = pageIndex * pageSize;
 
        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
 
        string sql = "select M.ExhibitionID,M.SystemID,M.TitleValue,M.ContentValue,M.ScopeValue,M.OrganizerValue,Country.CountryName,Area.AreaName,E.ExhibitionID,E.HttpUrl,E.StartDT,E.EndDT,E.ImageUrl from Country left join Area on Country.CountryID=Area.CountryID left join Pavilion on Area.AreaID=Pavilion.AreaID left join Exhibition E on E.PavilionID=Pavilion.PavilionID left join MultiLangExpo M on M.ExhibitionID=E.ExhibitionID where M.SystemID=1 and E.TypeID=1 and E.deleted=0 and StartDT > getDate() order by StartDT Desc";
        SqlDataAdapter da = new SqlDataAdapter(sql,conn);
        DataSet ds = new DataSet();
        da.Fill(ds, firstPage, pageSize, "listall");
        DataTable dt = ds.Tables["listall"];
        AspNetPager1.RecordCount = getCount(); 
        rptList.DataSource = dt;
        rptList.DataBind();
    }
    private int getCount()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        string sql = "";
        sql = "select Count(E.ExhibitionID) from Country left join Area on Country.CountryID=Area.CountryID left join Pavilion on Area.AreaID=Pavilion.AreaID left join Exhibition E on E.PavilionID=Pavilion.PavilionID left join MultiLangExpo M on M.ExhibitionID=E.ExhibitionID where M.SystemID=1 and E.TypeID=1 and E.deleted=0 and StartDT > getDate()";
        SqlCommand com = new SqlCommand(sql, con);
        con.Open();
        int temp = Convert.ToInt32(com.ExecuteScalar());
        con.Close();
        return temp;
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多