datalist 分页绑定问题

kay1990 2010-12-29 05:11:54
加载时弹出一个datalist,可以进行分页,但是经过条件查询后,弹出的新的datalist进行分页时,按下一页出现的是加载时datalist数据源,如何把它改成经过条件查询后的数据源?(补充:分页按钮为 HyperLink)
...全文
95 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
宝贝快乐 2010-12-30
  • 打赏
  • 举报
回复
session传值, if (!IsPostBack)
{


RadionButtonBind();
DropDownListBind();
if (Session["name"] != null)
{
this.DropDownList1.SelectedIndex = Convert.ToInt32(Session["name"].ToString());
DropDownList1_SelectedIndexChanged(null, null);
}
else if (Session["id"] !=null)
{
this.RadioButtonList1.SelectedIndex = Convert.ToInt32( Session["id"].ToString());
RadioButtonList1_SelectedIndexChanged(null, null);
}
else if (Session["name1"] != null)
{
this.DropDownList1.SelectedIndex = Convert.ToInt32(Session["name1"].ToString());
DropDownList1_SelectedIndexChanged(null, null);
}
else if (Session["id1"] != null)
{
this.RadioButtonList1.SelectedIndex = Convert.ToInt32(Session["id1"].ToString());
RadioButtonList1_SelectedIndexChanged(null, null);
}
else if (Session["name2"] != null)
{
this.DropDownList1.SelectedIndex = Convert.ToInt32(Session["name2"].ToString());
DropDownList1_SelectedIndexChanged(null, null);
}
else if (Session["id2"] != null)
{
this.RadioButtonList1.SelectedIndex = Convert.ToInt32(Session["id2"].ToString());
RadioButtonList1_SelectedIndexChanged(null, null);
}
else if (Session["name3"] != null)
{
this.DropDownList1.SelectedIndex = Convert.ToInt32(Session["name3"].ToString());
DropDownList1_SelectedIndexChanged(null, null);
}
else if (Session["id3"] != null)
{
this.RadioButtonList1.SelectedIndex = Convert.ToInt32(Session["id3"].ToString());
RadioButtonList1_SelectedIndexChanged(null, null);
}



}
kay1990 2010-12-30
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 xiaoqiu1234 的回复:]
你可以把你邮箱写下 我有源程序发你下
[/Quote]
wzq1157@126.com
kay1990 2010-12-30
  • 打赏
  • 举报
回复
wzq1157@126.com
xiaoqiu1234 2010-12-30
  • 打赏
  • 举报
回复
你可以把你邮箱写下 我有源程序发你下
luyuwei2008 2010-12-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wuyq11 的回复:]
使用aspnetpager分页控件,单步跟踪看看page的数据
绑定时根据条件查询数据
或viewstate记录
[/Quote]
正解!!
walking56489 2010-12-29
  • 打赏
  • 举报
回复
再重新查一遍
wuyq11 2010-12-29
  • 打赏
  • 举报
回复
使用aspnetpager分页控件,单步跟踪看看page的数据
绑定时根据条件查询数据
或viewstate记录
kay1990 2010-12-29
  • 打赏
  • 举报
回复
     protected void datebind()
{


}



//dropdownlist查询
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

if (DropDownList1.SelectedIndex == 0)
{
if (RadioButtonList1.SelectedIndex == 0)
{
DataListBind();
}
else
{
Model.RoomState rs = new Model.RoomState();
BLL.BRoomInfo bri = new BLL.BRoomInfo();
rs.RState_State1 = RadioButtonList1.SelectedValue.ToString();

DataSet ds = bri.selectbystate(rs);

PagedDataSource page = new PagedDataSource();
page.DataSource = ds.Tables[0].DefaultView;
page.AllowPaging = true; page.PageSize = 10;
int curpage;

if (Request.QueryString["page"] != null)
{
curpage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curpage = 1;
}

page.CurrentPageIndex = curpage - 1;

int totalpage = page.PageCount;

int tnum = page.DataSourceCount;

int eachpage = page.Count;

lblcurpage.Text = "第" + curpage.ToString() + "/" + totalpage.ToString() + "页";

lbltnum.Text = "共:" + tnum.ToString() + "条记录";

if (page.CurrentPageIndex != 0)
{
hlfirst.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(1);
}

if (page.CurrentPageIndex != totalpage - 1)
{
hllast.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(totalpage);
}

if (!page.IsFirstPage)
{
hlpre.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(curpage - 1);
}

if (!page.IsLastPage)
{
hlnext.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(curpage + 1);
}

DataList1.DataSource = page;
DataList1.DataBind();
}
}
else
{
if (RadioButtonList1.SelectedIndex == 0)
{
Model.FloorInfo fl = new Model.FloorInfo();
BLL.BRoomInfo bri = new BLL.BRoomInfo();
fl.Floor_Num1 = Convert.ToInt32(DropDownList1.SelectedValue);

DataSet ds = bri.selectallbyfloor(fl);

PagedDataSource page = new PagedDataSource();
page.DataSource = ds.Tables[0].DefaultView;
page.AllowPaging = true; page.PageSize = 10;
int curpage;

if (Request.QueryString["page"] != null)
{
curpage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curpage = 1;
}

page.CurrentPageIndex = curpage - 1;

int totalpage = page.PageCount;

int tnum = page.DataSourceCount;

int eachpage = page.Count;

lblcurpage.Text = "第" + curpage.ToString() + "/" + totalpage.ToString() + "页";

lbltnum.Text = "共:" + tnum.ToString() + "条记录";

if (page.CurrentPageIndex != 0)
{
hlfirst.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(1);
}

if (page.CurrentPageIndex != totalpage - 1)
{
hllast.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(totalpage);
}

if (!page.IsFirstPage)
{
hlpre.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(curpage - 1);
}

if (!page.IsLastPage)
{
hlnext.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(curpage + 1);
}

DataList1.DataSource = page;
DataList1.DataBind();
ds.Tables[0].Dispose();
}
else
{
Model.FloorInfo fl = new Model.FloorInfo();
Model.RoomState rs = new Model.RoomState();
BLL.BRoomInfo bri = new BLL.BRoomInfo();


fl.Floor_Num1 = Convert.ToInt32(DropDownList1.SelectedValue);
rs.RState_State1 = RadioButtonList1.SelectedValue.ToString();
DataSet ds = bri.select(fl, rs);

PagedDataSource page = new PagedDataSource();
page.DataSource = ds.Tables[0].DefaultView;
page.AllowPaging = true;
page.PageSize = 10;
int curpage;

if (Request.QueryString["page"] != null)
{
curpage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curpage = 1;
}

page.CurrentPageIndex = curpage - 1;

int totalpage = page.PageCount;

int tnum = ds.Tables[0].Rows.Count;

int eachpage = page.Count;

lblcurpage.Text = "第" + curpage.ToString() + "/" + totalpage.ToString() + "页";

lbltnum.Text = "共:" + tnum.ToString() + "条记录";

if (page.CurrentPageIndex != 0)
{
hlfirst.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(1);
}

if (page.CurrentPageIndex != totalpage - 1)
{
hllast.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(totalpage);
}

if (!page.IsFirstPage)
{
hlpre.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(curpage - 1);
}

if (!page.IsLastPage)
{
hlnext.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(curpage + 1);
}

DataList1.DataSource = page;
DataList1.DataBind();
}
}
}
接上楼
kay1990 2010-12-29
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace website.RoomManager
{
public partial class ManagerRoomDetail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{


RadionButtonBind();
DataListBind();

DropDownListBind();

}
}


protected void RadionButtonBind()
{
BLL.BRommState brs = new BLL.BRommState();
DataSet ds = brs.selectall();


RadioButtonList1.Items.Add("所有");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string str=ds .Tables [0].Rows [i][1].ToString ();
RadioButtonList1.Items.Add(str);
}

}

protected void DetailsViewBind()
{
Panel1.Visible = true;
Model.RoomInfo ri = new Model.RoomInfo();
BLL.BRoomInfo bri = new BLL.BRoomInfo();
ri.Room_Id1 = roomid;
DataSet ds = bri.selectbyid(ri);

this.DetailsView2.DataSource=ds.Tables[0].DefaultView;
DetailsView2.DataBind();



}

protected void DropDownListBind()
{
BLL.BFloor bfl = new BLL.BFloor();
DataSet ds= bfl.selectall();

DropDownList1.Items.Add("请选择楼层");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{

string str=ds.Tables [0].Rows [i ][1].ToString ();
DropDownList1.Items.Add(str);
}
}

//类型绑定
protected void TypeBind()
{
BLL.BRoomType brt = new BLL.BRoomType();
DataSet ds= brt.selectalltype();
DropDownList ddl=(DropDownList )DetailsView2 .Rows [1].Cells [1].FindControl ("ddltype");
ddl.Items.Add(typename );
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string str = ds.Tables[0].Rows[i][0].ToString();
ddl.Items.Add(str);
}

}


//根据用户输入绑定楼层
protected void FloorBind()
{
Model.RoomInfo ri = new Model.RoomInfo();
BLL.BFloor bfl = new BLL.BFloor();
TextBox txtbox=(TextBox)DetailsView2.Rows[0].Cells[1].FindControl("txtboxid") ;

if (txtbox .Text =="" )
{
((DropDownList)DetailsView2.Rows[2].Cells[1].FindControl("ddlfloor")).Items.Add("未分配楼层");
}
else
{
ri.Room_Id1 = ((TextBox)(DetailsView2.Rows[0].Cells[1].FindControl("txtboxid"))).Text;
DataSet ds = bfl.selectfloor(ri );
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
string str = ds.Tables[0].Rows[j][0].ToString();
((DropDownList)(DetailsView2.Rows[2].Cells[1].FindControl("ddlfloor"))).Items.Add(str);

}
}

}

//全部绑定
protected void DataListBind()
{
BLL.BRoomInfo emp = new BLL.BRoomInfo();
DataSet ds = emp.selectall();


PagedDataSource page = new PagedDataSource();
page.DataSource = ds.Tables[0].DefaultView;
page.AllowPaging = true; page.PageSize = 10;
int curpage;

if (Request.QueryString["page"] != null)
{
curpage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curpage = 1;
}

page.CurrentPageIndex = curpage - 1;

int totalpage = page.PageCount;

int tnum = page.DataSourceCount;

int eachpage = page.Count;

lblcurpage.Text = "第" + curpage.ToString()+"/" + totalpage.ToString() + "页";

lbltnum.Text = "共:" + tnum.ToString() + "条记录";

if (page.CurrentPageIndex != 0)
{
hlfirst.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(1);
}

if (page.CurrentPageIndex !=totalpage -1)
{
hllast .NavigateUrl =Request .CurrentExecutionFilePath +"?page="+Convert .ToString (totalpage );
}

if (!page.IsFirstPage)
{
hlpre.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(curpage - 1);
}

if (!page.IsLastPage )
{
hlnext .NavigateUrl =Request .CurrentExecutionFilePath +"?page="+Convert .ToString (curpage +1);
}
if (page.IsLastPage)
{
hllast.Visible = false;
}
if (page.IsFirstPage)
{
hlfirst.Visible = false;
}
if (curpage > totalpage)
{
page.CurrentPageIndex = 0;
}

DataList1.DataSource = page;
DataList1.DataBind();
ds.Tables[0].Dispose();

}
kay1990 2010-12-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 super1021love 的回复:]
那就是你没有在load里面写!page.ispostback 加上这,然后分页重新绑定应该就好了
[/Quote]
我的代码里有这啊
super1021love 2010-12-29
  • 打赏
  • 举报
回复
那就是你没有在load里面写!page.ispostback 加上这,然后分页重新绑定应该就好了
kay1990 2010-12-29
  • 打赏
  • 举报
回复
重新帮定了好几次了,没有用啊
kay1990 2010-12-29
  • 打赏
  • 举报
回复
各位大大,帮帮忙啊!!!
新手啊,分不多,帮帮忙啊!
jypcxgzl 2010-12-29
  • 打赏
  • 举报
回复
重新绑定一下啊

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧