使用session在不同页面之间传递参数,sqldatasource按条件查询

来源:互联网 发布:浙江政务服务软件 编辑:程序博客网 时间:2024/05/22 12:46

1.如图1 所示用户设置预警参数,通过session将textbox输入的参数传入另一个页面,如图2所示:


图1

2.图1的后台代码如下:

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace WebApplication1{    public partial class WebForm19 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {            Session["Temp1"] = TextBox1.Text;            Session["Temp2"] = TextBox2.Text;            Session["Humid1"] = TextBox3.Text;            Session["Humid2"] = TextBox4.Text;            Session["Deform1"] = TextBox5.Text;            Session["Deform2"] = TextBox6.Text;        }        protected void TextBox1_TextChanged(object sender, EventArgs e)        {        }        protected void Button4_Click(object sender, EventArgs e)        {            Session["Temp1"] = TextBox1.Text;            Session["Temp2"] = TextBox2.Text;            Session["Humid1"] = TextBox3.Text;            Session["Humid2"] = TextBox4.Text;            Session["Deform1"] = TextBox5.Text;            Session["Deform2"] = TextBox6.Text;        }    }}
3.如图2所示,左侧显示图1传入的预警参数,右侧通过添加数据源,选择查询的范围(在预警参数范围内),病通过Gridview控件显示在表格中


图2

4.图2的后台代码如下所示:

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Windows.Forms;using System.Windows.Forms.DataVisualization.Charting;using System.Data;using System.Data.SqlClient;namespace WebApplication1{    public partial class WebForm15 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {            //若管理员不设置预警参数,使用系统默认预警参数            if (Session["Temp1"] == null || Session["Temp2"] == null || Session["Humid1"] == null || Session["Humid2"] == null || Session["Deform1"] == null || Session["Deform2"] == null)            {                Label3.Text = Convert.ToString(15);                Label4.Text = Convert.ToString(25);                Label5.Text = Convert.ToString(40);                Label6.Text = Convert.ToString(60);                Label7.Text = Convert.ToString(4);                Label8.Text = Convert.ToString(9);            }            else            {                //显示WarningParameter1.aspx设置的预警参数                Label3.Text = Session["Temp1"].ToString();                Label4.Text = Session["Temp2"].ToString();                Label5.Text = Session["Humid1"].ToString();                Label6.Text = Session["Humid2"].ToString();                Label7.Text = Session["Deform1"].ToString();                Label8.Text = Session["Deform2"].ToString();                //根据预警参数筛选异常数据            }        }               protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)        {        }    }}


5.sqldatasource按条件查询

在Gridview点击新建数据源,选择数据库,选择数据表,选择数据列,添加where语句



0 0