Repeater分页显示
Repeater分页显示
简单的说,先从控件工具箱中拖入两个label(currten page当前页,count page总页),四个linkbuttion(首/下页/上页/尾页)。
无非就是+1 -1 的问题,
------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class gonggao : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.labPage.Text = "1";
this.contrlRepeater();
}
}
//获取指字符个数的字符
public string cuts(string aa,int bb)
{
if (aa.Length <= bb) { return aa; }
else { return aa.Substring(0, bb); }
}
//Repeater分页控制显示方法
public void contrlRepeater()
{
pb pb1 = new pb();
DataSet ss = new DataSet();
ss = pb1.returnDs("select top 200 [标题],[时间] from news");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ss.Tables["temptable"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 2;
pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
Repeater1.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;
}
Repeater1.DataBind();
}
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();
}
}
-----------------
uploadfile上传图片
.cs 界面代码
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
string name="b";//根据需要给上传的图片命名
int minsize=1;//上传文件的最低大小,单位kb
int maxsize=1000;//上传文件的最大大小,单位kb
protected void Page_Load(object sender, EventArgs e)
{
}
protected void upload_Click(object sender, EventArgs e)
{
string fileName, fileExtension, FullName;
if (UpImage.PostedFile != null)
{
if (UpImage.PostedFile.ContentLength != 0 && UpImage.PostedFile.ContentLength <= (1024 * maxsize) && UpImage.PostedFile.ContentLength >= (1024 * minsize))
{
fileName = System.IO.Path.GetFileName(UpImage.PostedFile.FileName);
fileExtension = System.IO.Path.GetExtension(fileName);
if (IsExtension(fileExtension))
{
try
{
FullName = name;
CreateDir("upLoadImg");
FullName = DateTime.Now.ToString("yyyyMM") + "/" + FullName;
UpImage.PostedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(@"UpFiles/upLoadImg/") + FullName);
}
catch (Exception ex)
{
Response.Write("<script language=javascript>alert('" + ex.Message + "');</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('上传的文件格式不对,请上传指定的文件格式!');</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('没有上传文件,或者文件太大!请重新上传!');</script>");
}
}
}