我先说一下我的问题吧,我有一张报名表和一张员工表,有一个下拉框可以查找已报名和未报名的员工,但是我的员工表里面有2W人,如果我选择未报名或已报名的话,它要加载很长时间才能显示出来,请问大家有没有什么优化的方法,我写的方法如下:
//查询按钮的事件
protected void btnselect_Click(object sender, EventArgs e)
{
string where = "";
tlgbpx.Model.P_XTYHB xtyhb = (tlgbpx.Model.P_XTYHB)Session["User"];
string yhbm = xtyhb.BMBM;
string BJID = "";
if (Request["BJID"] != "")
{
BJID = Request["BJID"].ToString();
}
if (XMtxt.Text.Trim() != "") //通过姓名查找
{
where += " and XM like '" + TYClass.StrFilter(XMtxt.Text.Trim()) + "%'";
}
else
{
if (DropDownList1.SelectedItem.Text == "已报名") //查找已报名人员
{
List<tlgbpx.Model.P_BMB> listBMB = new List<P_BMB>();
if (DWtxt.Text.Trim() != "")
{
List<tlgbpx.Model.LZ_DWJBXX> listDWJBXX = tlgbpx.BLL.LZ_DWJBXX.getLiseByWHERE(" where dwmc like '" + TYClass.StrFilter(DWtxt.Text.Trim()) + "%'");
if (listDWJBXX.Count > 0)
{
where += " and dwbsm in(";
for (int i = 0; i < listDWJBXX.Count; i++)
{
where += "'" + listDWJBXX[i].DWBSM + "',";
}
where = where.Substring(0, where.Length - 1) + ")";
}
}
listBMB = tlgbpx.BLL.BMB.getListBMBByWHERE(" where BJID='" + BJID + "'");
if (listBMB.Count > 0)
{
where += " and rybm in(";
for (int i = 0; i < listBMB.Count; i++)
{
tlgbpx.Model.P_BMB bmb = listBMB[i];
where += "'" + bmb.RYBM + "',";
}
where = where.Substring(0, where.Length - 1) + ")";
}
}
if (DropDownList1.SelectedItem.Text == "--请选择--")
{
if (DWtxt.Text.Trim() != "")
{
List<tlgbpx.Model.LZ_DWJBXX> listDWJBXX = tlgbpx.BLL.LZ_DWJBXX.getLiseByWHERE(" where dwmc like '" + TYClass.StrFilter(DWtxt.Text.Trim()) + "%'");
if (listDWJBXX.Count > 0)
{
where += " and dwbsm in(";
for (int i = 0; i < listDWJBXX.Count; i++)
{
where += "'" + listDWJBXX[i].DWBSM + "',";
}
where = where.Substring(0, where.Length - 1) + ")";
}
}
}
if (DropDownList1.SelectedItem.Text == "未报名") //查找未报名人员
{
List<tlgbpx.Model.GG_ZGJBXX> listZGJBXX = new List<tlgbpx.Model.GG_ZGJBXX>();
string acc = "";
if (DWtxt.Text.Trim() != "")
{
List<tlgbpx.Model.LZ_DWJBXX> listDWJBXX = tlgbpx.BLL.LZ_DWJBXX.getLiseByWHERE(" where dwmc like '" + TYClass.StrFilter(DWtxt.Text.Trim()) + "%'");
if (listDWJBXX.Count > 0)
{
acc = " and dwbsm in(";
for (int i = 0; i < listDWJBXX.Count; i++)
{
acc += "'" + listDWJBXX[i].DWBSM + "',";
}
acc = acc.Substring(0, acc.Length - 1) + ")";
}
}
listZGJBXX = tlgbpx.BLL.GG_ZGJBXX.getListByWHERE(" where 1=1 " + acc);
if (listZGJBXX.Count > 0)
{
string abc = "";
for (int i = 0; i < listZGJBXX.Count; i++)
{
tlgbpx.Model.P_BMB bmb = tlgbpx.BLL.BMB.getBMBByZGIDandBJID(listZGJBXX[i].RYBM, BJID);
if (bmb == null)
{
abc += "'" + listZGJBXX[i].RYBM + "',";
}
}
if (abc != "")
{
where += " and rybm in(" + abc.Substring(0, abc.Length - 1) + ")";
}
}
}
}
ViewState["where"] = where;
YGgetdatabind(ViewState["where"].ToString());
}//员工绑定的
void YGgetdatabind(string where)
{
string strSql = " where 1=1";
if (where != "")
{
strSql += where;
}
DataSet ds = tlgbpx.BLL.GG_ZGJBXX.getDataSet(strSql);
DataView dv = ds.Tables[0].DefaultView;
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = dv.Count;
AspNetPager1.PageSize = 15;
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize;
this.GridView1.DataSource = pds;
this.GridView1.DataBind();
}
//查询按钮的事件
protected void btnselect_Click(object sender, EventArgs e)
{
string where = "";
tlgbpx.Model.P_XTYHB xtyhb = (tlgbpx.Model.P_XTYHB)Session["User"];
string yhbm = xtyhb.BMBM;
string BJID = "";
if (Request["BJID"] != "")
{
BJID = Request["BJID"].ToString();
}
if (XMtxt.Text.Trim() != "") //通过姓名查找
{
where += " and XM like '" + TYClass.StrFilter(XMtxt.Text.Trim()) + "%'";
}
else
{
if (DropDownList1.SelectedItem.Text == "已报名") //查找已报名人员
{
List<tlgbpx.Model.P_BMB> listBMB = new List<P_BMB>();
if (DWtxt.Text.Trim() != "")
{
List<tlgbpx.Model.LZ_DWJBXX> listDWJBXX = tlgbpx.BLL.LZ_DWJBXX.getLiseByWHERE(" where dwmc like '" + TYClass.StrFilter(DWtxt.Text.Trim()) + "%'");
if (listDWJBXX.Count > 0)
{
where += " and dwbsm in(";
for (int i = 0; i < listDWJBXX.Count; i++)
{
where += "'" + listDWJBXX[i].DWBSM + "',";
}
where = where.Substring(0, where.Length - 1) + ")";
}
}
listBMB = tlgbpx.BLL.BMB.getListBMBByWHERE(" where BJID='" + BJID + "'");
if (listBMB.Count > 0)
{
where += " and rybm in(";
for (int i = 0; i < listBMB.Count; i++)
{
tlgbpx.Model.P_BMB bmb = listBMB[i];
where += "'" + bmb.RYBM + "',";
}
where = where.Substring(0, where.Length - 1) + ")";
}
}
if (DropDownList1.SelectedItem.Text == "--请选择--")
{
if (DWtxt.Text.Trim() != "")
{
List<tlgbpx.Model.LZ_DWJBXX> listDWJBXX = tlgbpx.BLL.LZ_DWJBXX.getLiseByWHERE(" where dwmc like '" + TYClass.StrFilter(DWtxt.Text.Trim()) + "%'");
if (listDWJBXX.Count > 0)
{
where += " and dwbsm in(";
for (int i = 0; i < listDWJBXX.Count; i++)
{
where += "'" + listDWJBXX[i].DWBSM + "',";
}
where = where.Substring(0, where.Length - 1) + ")";
}
}
}
if (DropDownList1.SelectedItem.Text == "未报名") //查找未报名人员
{
List<tlgbpx.Model.GG_ZGJBXX> listZGJBXX = new List<tlgbpx.Model.GG_ZGJBXX>();
string acc = "";
if (DWtxt.Text.Trim() != "")
{
List<tlgbpx.Model.LZ_DWJBXX> listDWJBXX = tlgbpx.BLL.LZ_DWJBXX.getLiseByWHERE(" where dwmc like '" + TYClass.StrFilter(DWtxt.Text.Trim()) + "%'");
if (listDWJBXX.Count > 0)
{
acc = " and dwbsm in(";
for (int i = 0; i < listDWJBXX.Count; i++)
{
acc += "'" + listDWJBXX[i].DWBSM + "',";
}
acc = acc.Substring(0, acc.Length - 1) + ")";
}
}
listZGJBXX = tlgbpx.BLL.GG_ZGJBXX.getListByWHERE(" where 1=1 " + acc);
if (listZGJBXX.Count > 0)
{
string abc = "";
for (int i = 0; i < listZGJBXX.Count; i++)
{
tlgbpx.Model.P_BMB bmb = tlgbpx.BLL.BMB.getBMBByZGIDandBJID(listZGJBXX[i].RYBM, BJID);
if (bmb == null)
{
abc += "'" + listZGJBXX[i].RYBM + "',";
}
}
if (abc != "")
{
where += " and rybm in(" + abc.Substring(0, abc.Length - 1) + ")";
}
}
}
}
ViewState["where"] = where;
YGgetdatabind(ViewState["where"].ToString());
}//员工绑定的
void YGgetdatabind(string where)
{
string strSql = " where 1=1";
if (where != "")
{
strSql += where;
}
DataSet ds = tlgbpx.BLL.GG_ZGJBXX.getDataSet(strSql);
DataView dv = ds.Tables[0].DefaultView;
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = dv.Count;
AspNetPager1.PageSize = 15;
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize;
this.GridView1.DataSource = pds;
this.GridView1.DataBind();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货