search.ascx.cs
上传用户:yawei0714
上传日期:2020-11-26
资源大小:1004k
文件大小:3k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

HTML/CSS

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. public partial class search : System.Web.UI.UserControl
  12. {
  13.     protected void Page_Load(object sender, EventArgs e)
  14.     {
  15.         if (!IsPostBack)
  16.         {
  17.             bindSearchType();         
  18.         }
  19.     }
  20.     //绑定信息类型下拉列表
  21.     public void bindSearchType()
  22.     {
  23.         string sql = "select distinct searchType,type from tb_Search";      
  24.         DataSet ds = dataOperate.getDataset(sql, "tb_Search");              
  25.         ddlSearchType.DataSource = ds.Tables["tb_Search"].DefaultView;        
  26.         ddlSearchType.DataTextField = "searchType";
  27.         ddlSearchType.DataValueField = "type";
  28.         ddlSearchType.DataBind();
  29.         bindKey(); 
  30.     }
  31.     //自定义方法绑定关键字下拉列表
  32.     public void bindKey()
  33.     {
  34.         //获取当前选择的信息类型的表名
  35.         string type = ddlSearchType.SelectedValue.ToString();
  36.         string sql = "select searchKey,keyword from tb_Search where type='" + type + "'";
  37.         //调用数据库操作类中getDataset方法并获取返回的数据集
  38.         DataSet ds = dataOperate.getDataset(sql, "tb_Search");          
  39.         //绑定关键字类别的DropDownList控件的数据源
  40.         ddlKeyType.DataSource = ds.Tables["tb_Search"].DefaultView;   
  41.         //绑定关键字类别DropDownList控件文本的字段名
  42.         ddlKeyType.DataTextField = "searchKey";
  43.         //绑定关键字类别DropDownList控件值的字段名   
  44.         ddlKeyType.DataValueField = "keyword";
  45.         ddlKeyType.DataBind();
  46.         bindTerminal();                 //调用自定义方法是否显示到达地文本框       
  47.     }
  48.      //根据信息类型绑定关键字下拉列表
  49.     protected void ddlSearchType_SelectedIndexChanged(object sender, EventArgs e)
  50.     {
  51.         bindKey();      
  52.     }
  53.     //显示到达地文本框
  54.     public void bindTerminal()
  55.     {
  56.         //判断关键字类型是否选择了出发地
  57.         if (ddlKeyType.SelectedValue.ToString() == "Start")
  58.         {
  59.             txtTerminal.Text = "";  //清空到达地文本框
  60.             labTerminal.Visible = true;  
  61.             txtTerminal.Visible = true;
  62.         }
  63.         else
  64.         {
  65.             labTerminal.Visible = false;
  66.             txtTerminal.Visible = false;
  67.         }              
  68.     }
  69.          
  70.     protected void ddlKeyType_SelectedIndexChanged(object sender, EventArgs e)
  71.     {
  72.         bindTerminal(); 
  73.     }
  74.     protected void Button1_Click(object sender, EventArgs e)
  75.     {
  76.         string table = ddlSearchType.SelectedValue.ToString();
  77.         string keyType = ddlKeyType.SelectedValue.ToString();
  78.         string keys = txtKey.Text;
  79.         string sql;
  80.         if (txtTerminal.Text != "")
  81.         {
  82.             sql = "select * from " + table + " where " + keyType + " like '%" + keys + "%' and  terminal like '%" + txtTerminal.Text + "%'";
  83.         }
  84.         else
  85.         {
  86.             sql = "select * from " + table + " where " + keyType + " like '%" + keys + "%'";
  87.         }
  88.         Session["searchSql"] = sql;
  89.         Session["searchType"] = ddlSearchType.SelectedValue.ToString();
  90.         Response.Redirect("searchList.aspx");
  91.     }
  92. }