问题描述
RadioListBox相当于是一个筛选器,比如可以查看“未通过名单”“通过名单”“所有名单”,然后单击一个选项就可用查看相应的一些数据,RadioListBox已经AutoPostBack了。数据绑定用的是Repeater来显示的。翻页的用的是Lable超链接,当我单击翻页链接的时候,本来地址是xxx.aspx?topage=2&npage=通过名单,表示我要查看第二页的通过名单的数据,可是一点击翻页后,RadioListBox就初始化到“所有名单”了,显示数据也变成了第二页的所有数据的东西了xxx.aspx?topage=2&npage=所有名单……现在求高手帮我解决这个问题,如何翻页后还是显示的当前的RadioListBox的所有数据???困扰我两天了……DataSetds=newDataSet();stringnpage=q("npage");stringswitchRB1=RB1.SelectedValue;intPageSize=2;intPageCount,RecordCount;intToPage=Convert.ToInt32(Request.QueryString["ToPage"]);stringpagesql=null,sql=null;switch(switchRB1){case"未通过审核":sql="selectcount(id)fromCompany_BasemeanswhereisPast='未通过'";break;case"通过审核":sql="selectcount(id)fromCompany_BasemeanswhereisPast='通过'";break;case"企业总数":sql="selectcount(id)fromCompany_Basemeans";break;case"申请图招":sql="selectcount(id)fromCompany_Basemeanswherepiczp='申请通过图招'";break;}stringsqlstr=ConfigurationManager.ConnectionStrings["0745Job"].ToString();SqlConnectionconn=newSqlConnection(sqlstr);SqlCommandMyComm=newSqlCommand(sql,conn);conn.Open();RecordCount=Convert.ToInt32(MyComm.ExecuteScalar());conn.Close();if(RecordCount%PageSize!=0){PageCount=RecordCount/PageSize+1;}else{PageCount=RecordCount/PageSize;}if(ToPage==Convert.ToInt32(null)){ToPage=1;}if(ToPage>PageCount){ToPage=PageCount;}if(ToPage<=1){switch(switchRB1){case"未通过审核":pagesql="select....";break;case"通过审核":pagesql="select....";break;case"企业总数":pagesql="select....";break;case"申请图招":pagesql="select....";break;}}else{switch(switchRB1){case"未通过审核":pagesql="select....";break;case"通过审核":pagesql="select....";break;case"企业总数":pagesql="select....";break;case"申请图招":pagesql="select...."break;}}if(ToPage<=1){LinkPrev.Enabled=false;Linkhead.Enabled=false;CurrentPage.Text="1";}else{LinkPrev.Enabled=true;LinkPrev.NavigateUrl="?ToPage="+(ToPage-1)+"&npage="+switchRB1;Linkhead.Enabled=true;Linkhead.NavigateUrl="?ToPage=1&npage="+switchRB1;}if(ToPage>=PageCount){LinkFoot.Enabled=false;LinkNext.Enabled=false;CurrentPage.Text=PageCount.ToString();}else{LinkFoot.Enabled=true;LinkFoot.NavigateUrl="?ToPage="+PageCount+"&npage="+switchRB1;LinkNext.Enabled=true;LinkNext.NavigateUrl="?ToPage="+(ToPage+1)+"&npage="+switchRB1;}//**********************Label控件绑定**********************TotalPage.Text=Convert.ToString(PageCount);CurrentPage.Text=Convert.ToString(ToPage);LbRecord.Text=RecordCount.ToString();LbPageRecord.Text=PageSize.ToString();//**********************数据绑定**********************SqlDataAdapterda=newSqlDataAdapter(pagesql,conn);da.Fill(ds,"ShowPage");RP1.DataSource=ds.Tables["ShowPage"].DefaultView;RP1.DataBind();
解决方案
解决方案二:
既然你把查询方式通过QueryString跨页面提交了,那么在页面的Page_Load事件里添加修改RadioButtonlist的代码://Page_Loadeventif(!string.IsNullOrEmpty(Request.QueryString["npage"]){//增加修改RadioButtonList的代码switch(Request.QueryString["npage"]){case"...":}}else{}
解决方案三:
可以用viewstate/session之类的保存他的状态,然后在开始前判断是否有值---
解决方案四:
在Page_load里面维护radiobutton的状态。
解决方案五:
在Page_load里面维护radiobutton的状态;将接受的Request.QueryString["npage"]不为空的值赋值给RadioListBox.SelectValue,分页也是。不过你的需求似乎表达的还不太明确!页面是怎么设计的,需要什么样的功能等再说的明确点
解决方案六:
说的很明确了啊,根据RadioListBox的选项值来显示数据列表,然后翻页的时候应该还是显示的当前RadioListBox的选项值的数据列表。现在问题是翻页后,RadioListBox就被初始化了。比如“通过”“未通过”“所有”,当我选择“通过”查看所有通过的用户资料,就应该显示通过用户的数据列表,可是却显示了“所有”用户的数据列表,也就相当于被初始化了:(如果大家有类似的分页例子,希望能加我QQ:66477347,定当厚礼回报。