zoukankan      html  css  js  c++  java
  • 。net 之view筛选

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Caching;
    using System.Data;
    
    public partial class CACHE查询条件 : System.Web.UI.Page
    {
       
        protected void Button1_Click(object sender, EventArgs e)
        {
            string cond = "";
            if (this.DropDownList1.SelectedIndex > 0)
            {
                 cond += "stu_sex='" + this.DropDownList1.SelectedValue + "'";
              
            }
            else
            {
                 cond += "1=1";   
            }
    
            if (this.TextBox1.Text != "")
            {
                cond += " and age=" + this.TextBox1.Text;
            }
            ViewState["cond"] = cond;
            Page_Load(null, null);
        }
        //页面加载时,将DataSet插入到委托中去。
        protected void Page_Load(object sender, EventArgs e)
        {
    
            //首先从Cache中获取Dataset
            DataSet students = (DataSet)Cache["Students"];
            //如果Cache中不存在DataSet,则从数据库中获取DataSet,并添加到缓存中
            if (students == null)
            {
                students = GetStudentDataSet();
    
    
          
                //创建一个基于web.config配置文件的依赖,当该文件发生变化时,则从缓存中移除缓存项。
                CacheDependency cd = new CacheDependency(Server.MapPath("web.config"));
    
                //在Insert中指定该依赖项,并且指定缓存的优先级为高优先级,传递一个传托。
                Cache.Insert("Students", students, cd, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1));
            }
    
            DataView view = students.Tables[0].DefaultView;
            if (ViewState["cond"] != null)
            {
                view.RowFilter = ViewState["cond"].ToString();
            }
            GridView1.DataSource = view;
            //GridView1.DataSource = students;
    
            GridView1.DataBind();
        }
        /// <summary>
        /// 从数据库中获取产品信息,并返回一个DataSet对象
        /// </summary>
        /// <returns></returns>
        protected DataSet GetStudentDataSet()
        {
            string sql = "select * from t_student";
            DataSet ds = DBHelper.SqlHelper.ExecuteDataSetText(sql, null);
            return ds;
        }
    }
    

      

  • 相关阅读:
    遗传学详解及Matlab算法实现
    (转)非常好的理解遗传算法的例子
    Halcon学习笔记之支持向量机(二)
    Hough 变换
    主元分析PCA理论分析及应用
    Retinex图像增强算法
    Halcon学习笔记之支持向量机(一)
    阿里云OSS安装使用问题
    JS中双击和单击事件冲突解决
    JavaScript正则表达式应用---replace()
  • 原文地址:https://www.cnblogs.com/mengluo/p/6078295.html
Copyright © 2011-2022 走看看