protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDDL();
BindDDL2();
BindCBL();
form1.Target = "_blank";
}
}
private void BindDDL()
{//绑定年份
string sqlstr = "select distinct(Years) from Report";
DataSet ds = db.GetDS(sqlstr);
this.DropDownList1.DataSource = ds;
this.DropDownList1.DataTextField = "Years";
this.CheckBoxList1.DataValueField = "Years";
this.DropDownList1.DataBind();
}
private void BindDDL2()
{//绑定单位
string sqlstr = "select distinct(Adddepname) from Report where Adddepname<>''";
DataSet ds = db.GetDS(sqlstr);
this.DropDownList2.DataSource = ds;
this.DropDownList2.DataTextField = "Adddepname";
this.DropDownList2.DataValueField = "Adddepname";
this.DropDownList2.DataBind();
//this.DropDownList2.Items.Insert(0, new ListItem("--请选择--", "-1"));
}
private void BindCBL()
{//绑定多选按钮
string sqlstr = "select distinct(Months) from Report";
DataSet ds = db.GetDS(sqlstr);
this.CheckBoxList1.DataSource = ds;
this.CheckBoxList1.DataTextField = "Months";
this.CheckBoxList1.DataValueField = "Months";
this.CheckBoxList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{//跳转按钮
Response.Redirect("SelectTongJi.aspx?dwmc='" + DropDownList2.SelectedValue + "'&Years='"+DropDownList1.SelectedValue+"'&Months='"+CheckBoxList1.SelectedValue+"'");
}
上面是我的第一个页面
下面是我的第二个页面
protected void Page_Load(object sender, EventArgs e)
{
TJ();
}
private void TJ()
{
string sqlselect = "select sum([A]) as A,sum([B]) as B, sum([C]) as C, sum([D]) as D, sum([E]) as E, sum([F]) as F, sum([G]) as G, sum([H]) as H, sum([I]) as I, sum([J]) as J, sum([K]) as K, sum([L]) as L, sum([M]) as M, sum([N]) as N, sum([O]) as O, sum([P]) as P, sum([Q]) as Q, sum([R]) as R, sum([S]) as S, sum([S]) as T, sum([T]) as T, sum([U]) as U from Report where Years="+Request.QueryString["Years"].ToString()+" and (Months=1 or Months=2) and Adddepname="+Request.QueryString["dwmc"].ToString()+" group by Line";
DataSet ds = db.GetDS(sqlselect);
}
大家不用想我的SQL语句太长,我主要想让大家看的是红色的部分,多选按钮CheckBoxList1 例如我选择1和3,那么我第二个页要把值接过来。我主要就是想在第二个页面接到CheckBoxList1的值。小弟刚从学校毕业,刚上班,什么也不会,小弟在线等。
{
if (!IsPostBack)
{
BindDDL();
BindDDL2();
BindCBL();
form1.Target = "_blank";
}
}
private void BindDDL()
{//绑定年份
string sqlstr = "select distinct(Years) from Report";
DataSet ds = db.GetDS(sqlstr);
this.DropDownList1.DataSource = ds;
this.DropDownList1.DataTextField = "Years";
this.CheckBoxList1.DataValueField = "Years";
this.DropDownList1.DataBind();
}
private void BindDDL2()
{//绑定单位
string sqlstr = "select distinct(Adddepname) from Report where Adddepname<>''";
DataSet ds = db.GetDS(sqlstr);
this.DropDownList2.DataSource = ds;
this.DropDownList2.DataTextField = "Adddepname";
this.DropDownList2.DataValueField = "Adddepname";
this.DropDownList2.DataBind();
//this.DropDownList2.Items.Insert(0, new ListItem("--请选择--", "-1"));
}
private void BindCBL()
{//绑定多选按钮
string sqlstr = "select distinct(Months) from Report";
DataSet ds = db.GetDS(sqlstr);
this.CheckBoxList1.DataSource = ds;
this.CheckBoxList1.DataTextField = "Months";
this.CheckBoxList1.DataValueField = "Months";
this.CheckBoxList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{//跳转按钮
Response.Redirect("SelectTongJi.aspx?dwmc='" + DropDownList2.SelectedValue + "'&Years='"+DropDownList1.SelectedValue+"'&Months='"+CheckBoxList1.SelectedValue+"'");
}
上面是我的第一个页面
下面是我的第二个页面
protected void Page_Load(object sender, EventArgs e)
{
TJ();
}
private void TJ()
{
string sqlselect = "select sum([A]) as A,sum([B]) as B, sum([C]) as C, sum([D]) as D, sum([E]) as E, sum([F]) as F, sum([G]) as G, sum([H]) as H, sum([I]) as I, sum([J]) as J, sum([K]) as K, sum([L]) as L, sum([M]) as M, sum([N]) as N, sum([O]) as O, sum([P]) as P, sum([Q]) as Q, sum([R]) as R, sum([S]) as S, sum([S]) as T, sum([T]) as T, sum([U]) as U from Report where Years="+Request.QueryString["Years"].ToString()+" and (Months=1 or Months=2) and Adddepname="+Request.QueryString["dwmc"].ToString()+" group by Line";
DataSet ds = db.GetDS(sqlselect);
}
大家不用想我的SQL语句太长,我主要想让大家看的是红色的部分,多选按钮CheckBoxList1 例如我选择1和3,那么我第二个页要把值接过来。我主要就是想在第二个页面接到CheckBoxList1的值。小弟刚从学校毕业,刚上班,什么也不会,小弟在线等。
解决方案 »
- GridView绑定linq之后,怎么新增一行
- 向数据库insert时提示“将参数值从String转换到DateTime”错误
- 如何动态创建
- WPF 消息响应机制遇到了问题
- 求解 “访问性不一致”及其解决方法
- 如何让新的安装程序自动卸载旧版本的安装文件
- SqlTransaction.Rollback的用处是什么?
- 请教多线程performance的问题
- [请问] 什么方法可以在服务器端(cs)文件里面+一些代码或则是一些方法呢? (开发服务器控件)
- 关于一些在C#中模糊的概念?
- CE usb同步 PC SOCKET 通讯
- 求助!关于视频拍照如何加上自己公司标签的问题!!!大家帮忙!!谢谢先!!
{
str+=li.Checked?li.Value+",":"";
}
传递到第二个页面?id=str;
使用in () 查询数据
在你的Button1_Click事件里写代码
foreach(ListItem li in checlboxlist.Items)
{
str+=li.Checked?li.Value+",":"";
}
Response.Redirect("SelectTongJi.aspx?dwmc='" + DropDownList2.SelectedValue + "'&Years='"+DropDownList1.SelectedValue+"'&Months='"+str+"'");然后在你的第2个页面中将TJ函数修改成
private void TJ()
{
string sqlselect = string.Format("select sum([A]) as A,sum([B]) as B, sum([C]) as C, sum([D]) as D, sum([E]) as E, sum([F]) as F, sum([G]) as G, sum([H]) as H, sum([I]) as I, sum([J]) as J, sum([K]) as K, sum([L]) as L, sum([M]) as M, sum([N]) as N, sum([O]) as O, sum([P]) as P, sum([Q]) as Q, sum([R]) as R, sum([S]) as S, sum([S]) as T, sum([T]) as T, sum([U]) as U from Report where Years="+Request.QueryString["Years"]+" [color=#FF0000]and (Months in {0}) and Adddepname="+Request.QueryString["dwmc"]+" group by Line",Request.QueryString["Months"]);
DataSet ds = db.GetDS(sqlselect);
}
Request.QueryString["dwmc"].ToString() 这种写法是后面的.ToString()是多余的,以后不要加上了,保证代码的可读性!
当前上下文中不存在名称“checlboxlist”
foreach (ListItem li in CheckBoxList.Items)//报错:错误 399 非静态的字段、方法或属性“System.Web.UI.WebControls.ListControl.Items.get”要求对象引用 D:\经保\内网\UI\UI\SearchCount\report\tongJi.aspx.cs 56 33 D:\...\UI\ {
str += li.Checked ? li.Value + "," : "";//报错错误 400 当前上下文中不存在名称“str” D:\经保\内网\UI\UI\SearchCount\report\tongJi.aspx.cs 58 13 D:\...\UI\
还有错误 401 “System.Web.UI.WebControls.ListItem”并不包含“Checked”的定义 D:\经保\内网\UI\UI\SearchCount\report\tongJi.aspx.cs 58 23 D:\...\UI\ }