denuvead之.NET学习之旅

叁叁煮酒苦练室

c# repeater分页代码(比第一种效果好)

Default.aspx

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication1
...{
    
public partial class _Default : System.Web.UI.Page
    
...{


        
protected void Page_Load(object sender, EventArgs e)
        
...{
            
if (!IsPostBack)
            
...{
                
this.labPage.Text = "1";
                
this.contrlRepeater();
            }

        }



        
//Repeater分页控制显示方法 
        public void contrlRepeater()
        
...{
            DataSet ds 
= Portfolio.GetHistory(23);
            PagedDataSource pds 
= new PagedDataSource();
            pds.DataSource 
= ds.Tables[0].DefaultView;
            pds.AllowPaging 
= true;
            pds.PageSize 
= 2;
            pds.CurrentPageIndex 
= Convert.ToInt32(this.labPage.Text) - 1;
            rpPortfolioHistory.DataSource 
= pds;
            LabCountPage.Text 
= pds.PageCount.ToString();
            labPage.Text 
= (pds.CurrentPageIndex + 1).ToString();
            
this.lbtnpritPage.Enabled = true;
            
this.lbtnFirstPage.Enabled = true;
            
this.lbtnNextPage.Enabled = true;
            
this.lbtnDownPage.Enabled = true;
            
if (pds.CurrentPageIndex < 1)
            
...{
                
this.lbtnpritPage.Enabled = false;
                
this.lbtnFirstPage.Enabled = false;
            }

            
if (pds.CurrentPageIndex == pds.PageCount - 1)
            
...{
                
this.lbtnNextPage.Enabled = false;
                
this.lbtnDownPage.Enabled = false;
            }

            rpPortfolioHistory.DataBind();
        }


        
//获取指字符个数的字符 
        public string cuts(string aa, int bb)
        
...{
            
if (aa.Length <= bb) ...return aa; }
            
else ...return aa.Substring(0, bb); }
        }



        
protected void lbtnpritPage_Click(object sender, EventArgs e)
        
...{
            
this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) - 1);
            
this.contrlRepeater();
        }

        
protected void lbtnFirstPage_Click(object sender, EventArgs e)
        
...{
            
this.labPage.Text = "1";
            
this.contrlRepeater();
        }

        
protected void lbtnDownPage_Click(object sender, EventArgs e)
        
...{
            
this.labPage.Text = this.LabCountPage.Text;
            
this.contrlRepeater();
        }


        
protected void lbtnNextPage_Click(object sender, EventArgs e)
        
...{
            
this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) + 1);
            
this.contrlRepeater();
        }

















        
//protected void Page_Load(object sender, EventArgs e)
        
//{
        
//    DataSet ds = Portfolio.GetHistory(23);
        
//    if (ds != null && ds.Tables[0] != null)
        
//    {
        
//        rpPortfolioHistory.DataSource = ds.Tables[0];
        
//        rpPortfolioHistory.DataBind();
        
//    }
        
//}

        
protected string FormatType(int TransactionType)
        
...{
            
if (TransactionType == 1)
                
return "观察";
            
else if (TransactionType == 2)
                
return "申购";
            
else if (TransactionType == 3)
                
return "申购";
            
else if (TransactionType == 4)
                
return "赎回";
            
else if (TransactionType == 5)
                
return "买入";
            
else if (TransactionType == 6)
                
return "卖出";
            
else if (TransactionType == 7)
                
return "现金分红";
            
else if (TransactionType == 8)
                
return "拆分";
            
else if (TransactionType == 9)
                
return "红利再投资";
            
else
                
return "未知交易";
        }

    }

}

Portfolio.cs

 

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace WebApplication1
...{
    
public class Portfolio
    
...{
        
public static DataSet GetHistory(int portfolioid)
        
...{
            SqlParameter[] parameters 
= ...{                 
                                            
new SqlParameter("@PortfolioId",SqlDbType.Int)
                                        }
;

            parameters[
0].Value = portfolioid;
            
return DbHelperSQL.RunProcedure("sp_GetportfolioHistory", parameters, "result");
        }

    }

}

阅读更多
文章标签: c# parameters null
个人分类: ASP.NET 学习小记
想对作者说点什么? 我来说一句

repeater分页代码(直接可用)

2009年05月06日 42KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭