自己写了个分页,有点问题,请大家看看
static string sql= " ";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sql = "select [id],[ss],[city],[qy],[pq],[house_name],[address],[hx],[wylx],[jz_area],[jg],[zxcd],[cx],[bs],[cq],[zj],[fk],[fy],[zhuangtai],[kf],[dq],[wt],[ly],[tdjb],[lpwq],[jj],[jd],[jcpt],[bzjc],[cont],[djdate],[gxdate],[ren],[phone],[telphone],[lc],[sumlc],[newold],[wygl],[jt],[pay],[email],[zs],[tuijian],[tuijian1],[niandai],[lc1],[lc2],[gs],[area1],[area2],[dj],[cjr],[lb],[cj],[tel1],[ren1],[pay1],[fx],[fx1],[dian],[salesname],[mjdw],[jgdw],[anjie],[xingzi],[dong],[menpai],[quanshu],[shi],[ting],[wei],[loupan],[jingqudizhi],[ishide] from HouseInfo where [ishide]=1 and [chuqiu]= '1 ' ";
getbind(sql);
}
}
public void getbind(string sql)
{
DataSet ds = new DataSet();
ds = open.getreader(sql);
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
int count = ds.Tables[0].Rows.Count;
objPds.AllowPaging = true;
objPds.PageSize = 10;
int CurPage;
if (Request.QueryString[ "Page "] != null)
CurPage = Convert.ToInt32(Request.QueryString[ "Page "]);
else
CurPage = 1;
objPds.CurrentPageIndex = CurPage - 1;
lblCurrentPage.Text =CurPage.ToString();
zongjilu.Text = count.ToString();
int sumye = count / 10 + 1;
sumyema.Text = sumye.ToString();
tiaomeiye.Text = "10 ";
if (!objPds.IsFirstPage)
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page= " + Convert.ToString(CurPage - 1);
if (!objPds.IsLastPage)
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page= " + Convert.ToString(CurPage + 1);
if(!objPds.IsFirstPage)
first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page= " + 1;
if (!objPds.IsLastPage)
end.NavigateUrl = Request.CurrentExecutionFilePath + "?Page= " + sumye;
Repeater1.DataSource = objPds;
Repeater1.DataBind();
}
protected void chaxun_Click1(object sender, EventArgs e)
{
string sql1 = " ";
string wuyeleixing = wylx.SelectedItem.Text; //物业类型
if (idhao.Text != null&&idhao.Text!= " ")
{
string id = idhao.Text.Trim(); //房源id号
sql1 += " and id= "+id;
}
if (dian.SelectedItem.Text != "请选择 ")
{
string dia = dian.SelectedItem.Text; //店
sql1 += "and dian= ' " + dia + " ' ";
}
string jia1 = jiage1.Text.Trim(); //价格1
string jia2 = jiage2.Text.Trim(); //价格2
if (jia1 == " " && jia2 != " ")
{
Response.Write( " <script> alert( '价格必须同步! ') </script> ");
}
else if (jia1 != " " && jia2 == " ")
{
Response.Write( " <script> alert( '价格必须同步! ') </script> ");
}
else if (jia1 != " " && jia2 != " ")
{
sql1 += " and pay> = " + jia1 + " and pay <= " + jia2;
}
string mj1 = mianji1.Text.Trim(); //面积1
string mj2 = mianji2.Text.Trim(); //面积2
if (mj1 == " " && mj2 != " ")
{
Response.Write( " <script> alert( '面积必须同步! ') </script> ");
}
else if (mj1 != " " && mj2 == " ")
{
Response.Write( " <script> alert( '面积必须同步! ') </script> ");
}
else if (mj1 != " " && mj2 != " ")
{
sql1 += " and jz_area> = " + mj1 + " and jz_area <= " + mj2;
}
string loucheng1 = lc1.Text.Trim(); //楼层1
string loucheng2 = lc2.Text.Trim(); //楼层2
if (loucheng1 == " " && loucheng2 != " ")
{
Response.Write( " <script> alert( '楼层必须同步! ') </script> ");
}
else if (loucheng1 != " " && loucheng2 == " ")
{
Response.Write( " <script> alert( '楼层必须同步! ') </script> ");
}
else if (loucheng1 != " " && loucheng2 != " ")
{
sql1 += " and lc> = " + loucheng1 + " and lc <= " + loucheng2;
}
//时间
if (zhuangtai.SelectedItem.Text != "请选择 ")
{
string zhuangta = zhuangtai.SelectedItem.Text; //状态
sql1 += " and zhuangtai= ' " + zhuangta + " ' ";
}
if (jianzhuniandai.SelectedItem.Text != "请选择 ")
{
string jznd = jianzhuniandai.SelectedItem.Text; // 建筑年代
sql1 += " and niandai= "+jznd;
}
if (shii.SelectedItem.Text != "请选择 ")
{
string shis = shii.SelectedItem.Text;
sql1 += " and shi= ' " + shis+ " ' ";
if (ting.SelectedItem.Text != "请选择 ")
{
string tingt=ting.SelectedItem.Text;
sql1 += " and ting= ' " + tingt+ " ' ";
}
if (wei.SelectedItem.Text != "请选择 ")
{
string weiw = wei.SelectedItem.Text;
sql1 += " and wei= ' " + weiw+ " ' ";
}
}
sql += sql1;
getbind(sql);
sql = "select [id],[ss],[city],[qy],[pq],[house_name],[address],[hx],[wylx],[jz_area],[jg],[zxcd],[cx],[bs],[cq],[zj],[fk],[fy],[zhuangtai],[kf],[dq],[wt],[ly],[tdjb],[lpwq],[jj],[jd],[jcpt],[bzjc],[cont],[djdate],[gxdate],[ren],[phone],[telphone],[lc],[sumlc],[newold],[wygl],[jt],[pay],[email],[zs],[tuijian],[tuijian1],[niandai],[lc1],[lc2],[gs],[area1],[area2],[dj],[cjr],[lb],[cj],[tel1],[ren1],[pay1],[fx],[fx1],[dian],[salesname],[mjdw],[jgdw],[anjie],[xingzi],[dong],[menpai],[quanshu],[shi],[ting],[wei],[loupan],[jingqudizhi],[ishide] from HouseInfo where [ishide]=1 and [chuqiu]= '1 ' ";
}
}
每次点击查询后,得到的分页,点击下一页就回到了初始化的分页 不知道是怎么回事啊
就算查出来的只有一页还是可以点击下一页 点击下一页就回到了初始化的分页
[解决办法]
点击分页事件里要重新帮顶数据源