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

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值