据说这个没有什么用,但是把这个搞懂了对datagri和datalist和有帮助,事业就笔记一下了。 ———————————-.cs页—————————————— private void Button1_Click(object sender, System.EventArgs e)
———-控件清单———
Panel Panel1;
Button Button1;
Button Button2;
Label Label1;
Label Label2;
Label Label3;
Label Label4;
Label Label5;
Repeater Repeater1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.Label1.Text=”1″;
this.fill();
}
}
private void fill()
{
int pag=Convert.ToInt32(this.Label1.Text);//设置当前页
SqlConnection con=new SqlConnection(“server=.;database=Northwind;uid=sa;pwd=980123;”);//实例化连接
SqlDataAdapter sda=new SqlDataAdapter();//建立一个数据适配器对象
sda.SelectCommand=new SqlCommand(“select * from Employees”,con);//实例化SelectCommand,并用他从数据库读出全部数据
DataSet ds=new DataSet();//定义一个数据集填充
sda.Fill(ds,”name”);//使用适配器填充数据集到本地表“name”
PagedDataSource ps=new PagedDataSource();//实例化一个PagedDataSource,这个本来是封装是DATAGRID里面的
ps.DataSource=ds.Tables[“name”].DefaultView;//设置他的数据源为ds.Tables[“name”].DefaultView数据视图
ps.AllowPaging=true;//允许分页
ps.PageSize=3;//每页显示数量
ps.CurrentPageIndex=pag-1;//当前页码,因为页是从0开始的,所以要减1
this.Button1.Enabled=true;//按钮当前状态
this.Button2.Enabled=true;
this.Label5.Text=ps.PageCount.ToString();
if(pag==1)
{
this.Button1.Enabled=false;//如果当前页是 1 ,上一页按钮不可用
}
if(pag==ps.PageCount)
{
this.Button2.Enabled=false;//如果当前页是最后一页 ,下一页按钮不可用
}
this.Repeater1.DataSource=ps;
this.Repeater1.DataBind();
}
窗体代码
private void Button2_Click(object sender, System.EventArgs e)
{
this.Label1.Text=((Convert.ToInt32(this.Label1.Text))+1).ToString();
this.fill();
}
{
this.Label1.Text=((Convert.ToInt32(this.Label1.Text))-1).ToString();
this.fill();
}
repeater读取数据并分页 _asp.net技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » repeater读取数据并分页 _asp.net技巧
相关推荐
- 暂无文章
