Repeater 控件 + 分页控件的使用_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Repeater 控件 + 分页控件的使用

Repeater 控件 + 分页控件的使用

 2013/7/12 10:14:42  porray  博客园  我要评论(0)
  • 摘要:前台页面A.aspx:<%@RegisterAssembly="AspNetPager"Namespace="Wuqi.Webdiyer"TagPrefix="webdiyer"%><asp:RepeaterID="rptList"runat="server"><ItemTemplate><divclass="saleexpo_div"onmouseover="this.style
  • 标签:Repeater 使用 控件

前台页面 A.aspx:

 

monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
 
<asp:Repeater ID="rptList" runat="server">
                             <ItemTemplate>
                                 <div class="saleexpo_div" onmouseover="this.style.backgroundColor='#FFFFEF'" onmouseout="this.style.backgroundColor=''">
                                     <div class="saleexpo_div1">
                                         <a href="ConventionDetailsApply.aspx?ConList=<%#Eval("ExhibitionID")%>" target="_blank">
                                             <img id="Img1" alt="" src='<%# myUtilitiesCS.ChkImageExist(0,"images/Exhibition/"+ DataBinder.Eval(Container.DataItem,"ImageUrl"),"images/NoPhoto_Exh.jpg")%>'
                                                 runat="server">
                                         </a>
                                     </div>
                                     <div class="saleexpo_div2">
                                         <h2>
                                             <a href='ConventionDetailsApply.aspx?ConList=<%#Eval("ExhibitionID")%>' target="_blank">
                                                 <asp:Label ID="Label1" runat="server" Text='<%#Eval("TitleValue") %>'></asp:Label>
                                             </a>
                                         </h2>
                                         <p>
                                             <span>展会时间:</span><%# DateTime.Parse(Eval("StartDT").ToString()).ToShortDateString()+"  至  "+DateTime.Parse(Eval("EndDT").ToString()).ToShortDateString() %>
                                         </p>
                                         <p>
                                             <span>展会地址:</span><%#Eval("CountryName").ToString()+Eval("AreaName").ToString()%>
                                         </p>
                                         <p>
                                             <span>展会简介:</span>
                                             <%#Eval("ContentValue") %>
                                         </p>
                                     </div>
                                 </div>
                                 <div class="saleexpo_divl">
                                 </div>
                             </ItemTemplate>
                         </asp:Repeater>

 

 

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

后台代码 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;
    }
}
发表评论
用户名: 匿名