这个查询的条件的值点击分页后该如何保存,即点击下一页是查询后的数据
把根据查询条件、pageIndex和pageSize返回数据集代码封装成一个方法,每次点击翻页或是查询时,传入需要的参数就行了吧
我以前也遇到过这问题,我是这样解决的
public partial class zhcxgl_cxshpsxx : System.Web.UI.Page
{
ConnClass mycon = new ConnClass();
static string SelectStr1 = "select b.XS_XM as '学生姓名',a.XS_LSH as '学生流水号',b.x_dm as '系部',b.zy_dm as '专业',b.bj_dm as '班级',a.SS_DM as '宿舍代码',a.QS_H as '寝室号',WP_DM as '物品代码',WP_SL as '物品数量',PK_JE as '赔款金额',a.PK_BZ as '赔款状态' from tbGWSH a join tbBDXS b on a.XS_LSH=b.XS_LSH order by a.XS_LSH";
static int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["sqlstr"] = "";
BindData(SelectStr1);
}
this.Label1.Text = "";
}
#region 数据绑定
void BindData(string sql)
{
try
{
this.GridView1.DataSource = mycon.myDataSet(sql); //绑定数据集
this.GridView1.DataBind();
}
catch (Exception exp)
{
Response.Write(exp.Message);
}
}
#endregion
#region 分頁
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
if (i == 1)
{
this.GridView1.PageIndex = e.NewPageIndex;
BindData(Session["sqlstr"].ToString());
}
else
{
this.GridView1.PageIndex = e.NewPageIndex;
BindData(SelectStr1);//重新绑定数据
}
}
#endregion
#region 清空文本
void ClearText()
{
this.TextBox1.Text = "";
this.TextBox2.Text = "";
this.txt_xsxm.Text = "";
this.TextBox4.Text = "";
this.TextBox5.Text = "";
this.TextBox6.Text = "";
for (int k = 0; k < RadioButtonList1.Items.Count; k++)
{
RadioButtonList1.Items[k].Selected = false;
}
}
#endregion
#region 清空查询条件
protected void Button3_Click(object sender, EventArgs e)
{
ClearText();
}
#endregion
#region 查询
protected void Button1_Click(object sender, EventArgs e)
{
i = 1;
string SelectStr = "select b.XS_XM as'学生姓名',a.XS_LSH as'学生流水号',b.x_dm as'系部',b.zy_dm as'专业',b.bj_dm as'班级',a.SS_DM as'宿舍代码',a.QS_H as'寝室号',WP_DM as'物品代码',WP_SL as '物品数量',PK_JE as'赔款金额',a.PK_BZ as'赔款状态' from tbGWSH a join tbBDXS b on a.XS_LSH=b.XS_LSH where 1=1";
if (TextBox1.Text.Trim() != "")
{
string x_dm = TextBox1.Text.Trim();//自定义系部
SelectStr += " and b.x_dm like '%" + x_dm + "%'";
}
if (TextBox2.Text.Trim() != "")
{
string zx_dm = TextBox2.Text.Trim();//自定义专业
SelectStr += " and b.zy_dm like '%" + zx_dm + "%'";
}
if (TextBox4.Text.Trim() != "")
{
string bj_dm = TextBox4.Text.Trim();//自定义班级
SelectStr += " and b.bj_dm like '%" + bj_dm + "%'";
}
if (TextBox5.Text.Trim() != "")
{
string SS_DM = TextBox5.Text.Trim();//自定义宿舍
SelectStr += " and a.ss_dm like '%" + SS_DM + "%'";
}
if (TextBox6.Text.Trim() != "")
{
string qs_h = TextBox6.Text.Trim();//自定义寝室号
SelectStr += " and a.qs_h='" + qs_h +"'";
}
if (this.txt_xsxm.Text.Trim() != "")
{
int ce = 0;
ce = mycon.CheckStr(txt_xsxm.Text.Trim());
if (ce == 1)
{
this.Label1.Text = "<script> alert('太子哥说:学生姓名不能含有特殊符号!');</script>";
return;
}
SelectStr += " and b.xs_xm like'" + this.txt_xsxm.Text.Trim() + "%'";
}
bool CheckList = false;
for(int k = 0;k < RadioButtonList1.Items.Count;k++)
{
if (RadioButtonList1.Items[k].Selected)
{
CheckList = true;
}
}
if (CheckList == true) //如果选择了RadioButtonList中的一项
{
SelectStr += " and PK_BZ=" + int.Parse(this.RadioButtonList1.SelectedItem.Value.ToString());
}
SelectStr += " order by a.XS_LSH,b.xs_xm"; //按照xs_lsh和xx_xm排序
Session["sqlstr"] = SelectStr;
try
{
BindData(SelectStr);//重新绑定数据源
}
catch (Exception exp)
{
Response.Write(exp.Message);
}
ClearText();
}
#endregion
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}