问题描述
前一页后一页都是正常翻页,但是下拉菜单页面跳转,不跳转,选了还是会跳转到当前所在页。不知道咋回事,谢谢各位大虾了usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclassDefault2:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){Bind();}privatevoidBind(){intcup=Convert.ToInt32(pagelbl.Text);SqlConnectioncon=newSqlConnection(ConfigurationManager.ConnectionStrings["temp"].ConnectionString);PagedDataSourcepds=newPagedDataSource();SqlDataAdaptersda=newSqlDataAdapter("select*frommain",con);DataSetds=newDataSet();sda.Fill(ds,"tabe");pds.DataSource=ds.Tables["tabe"].DefaultView;pds.AllowPaging=true;pds.CurrentPageIndex=0;pds.PageSize=10;DataList1.DataSource=pds;pds.CurrentPageIndex=cup-1;if(!IsPostBack){//判断页面是否第一次载入for(inti=1;i<=pds.PageCount;i++){//循环出页码pageddl.Items.Add(i.ToString());}}//下面主要是控制上下翻页按纽是否起用pageup.Enabled=true;pagedown.Enabled=true;if(pds.IsFirstPage){//如果是最前页,上页按纽不可用pageup.Enabled=false;}if(pds.IsLastPage){//如果是最后页,下页按纽不可用pagedown.Enabled=false;}//设置页码下拉菜单当前选中的值pageddl.SelectedItem.Text=cup.ToString();//终于可以绑定给DataList了DataList1.DataSource=pds;DataList1.DataKeyField="id";DataList1.DataBind();}protectedvoidpageddl_SelectedIndexChanged(objectsender,EventArgse){//页码下拉菜单事件pagelbl.Text=pageddl.SelectedItem.Text.ToString();//pageddl.SelectedValue=pagelbl.Text;Bind();}protectedvoidpagedown_Click(objectsender,EventArgse){//下页事件pagelbl.Text=Convert.ToString(Convert.ToInt32(pagelbl.Text)+1);Bind();}protectedvoidpageup_Click(objectsender,EventArgse){//上页事件pagelbl.Text=Convert.ToString(Convert.ToInt32(pagelbl.Text)-1);pageddl.SelectedValue=pagelbl.Text;Bind();}}
解决方案
解决方案二:
看看pageddl有没有回发到服务器,AutoPostBack设置为true
解决方案三:
是不是应该改一下控件的AutoPostBack属性为True
解决方案四:
有没有将AutoPostBack设为true
解决方案五:
if(!Page.IsPostBack){Bind();}