DropDownList的页面跳转

来源:百度知道 编辑:UC知道 时间:2024/05/11 16:21:05
public partial class SelfPatentMange : System.Web.UI.Page
{
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()
{
List<UserPatentComplex> kh = UserPatents.ReturnUPComplex();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = kh;
pds.AllowPaging = true;
pds.PageSize = 2;
pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
RepSelfPatent.DataSource = pds;
RepSelfPatent.DataBind();
LabCountPage.Tex

添加一个DropDownList1,用FOR循环添加LISTITEM,再为DropDownList1添加事件DropDownList1_SelectedIndexChanged(),记得将DropDownList1的AutoPostBack设为true。

下面的添加到contrlRepeater()中:

int pageall=pds.PageCount;
this.DropDownList1.Items.Clear();
for (int i = 1; i <= pageall; i++)
{
ListItem myli = new ListItem(i.ToString(), i.ToString());
myli.Enabled = true;
this.DropDownList1.Items.Add(myli);
}
this.DropDownList1.Enabled = true;
this.DropDownList1.AutoPostBack = true;

事件;
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.labPage.Text =this.DropDownList1.SelectedItem.Text;
this.contrlRepeater();
}