一個實現查詢功能的asp.net控制項

來源:互聯網
上載者:User

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace SearchControl
{
 /// <summary>
 /// Search 的摘要說明。
 /// </summary>
 
 public class Search : System.Web.UI.Control,INamingContainer
 {
  private System.Web.UI.WebControls.TextBox txtCondition;
  private System.Web.UI.WebControls.DropDownList ddlContent;
  private System.Web.UI.WebControls.Button btnSearch;
  public event System.EventHandler ToSearch;
  public Search()
  {
   this.EnsureChildControls();
   this.btnSearch.Click +=new EventHandler(btnSearch_Click);
  }
  public string Text
  {
   get{return this.txtCondition.Text;}
   set{this.txtCondition.Text=value;}
  }
  public object DataSource
  {
   get{return this.ddlContent.DataSource;}
   set{ddlContent.DataSource=value;}
  }
  public string DataTextField
  {
   get{return this.ddlContent.DataTextField;}
   set{this.ddlContent.DataTextField=value;}
  }
  public string DataValueField
  {
   get{return this.ddlContent.DataValueField;}
   set{this.ddlContent.DataValueField=value;}
  }
  public string SelectValue
  {
   get{return this.ddlContent.SelectedValue;}
   set{this.ddlContent.SelectedValue=value;}
  }
  public string SelectText
  {
   get{return this.ddlContent.SelectedItem.Text;}
  }
  public void DataBind()
  {
   this.ddlContent.DataBind();
  }
//  public ListItemCollection Items
//  {
//   get{return this.ddlContent.Items;}
//  }
  public string ButtonText
  {
   get{return this.btnSearch.Text;}
   set{this.btnSearch.Text=value;}
  }
  protected override void CreateChildControls()
  {
   txtCondition=new TextBox();
   this.ddlContent=new DropDownList();
   this.btnSearch=new Button();
   this.btnSearch.Text="查詢";
   System.Web.UI.WebControls.Literal []lt=new Literal[2];
   for(int i=0;i<lt.Length;i++)
   {
    lt[i]=new Literal();
    lt[i].Text="&nbsp;&nbsp;";
   }
   this.Controls.Add(txtCondition);
   this.Controls.Add(lt[0]);
   this.Controls.Add(this.ddlContent);
   this.Controls.Add(lt[1]);
   this.Controls.Add(this.btnSearch);
  }
  private void btnSearch_Click(object sender,EventArgs e)
  {
   if(ToSearch!=null)
   {
    ToSearch(this,e);
   }
  }
 }

主要實現功能是,在文字框中輸入查詢內容,下拉框中可選取查詢查詢範圍,比如分類,時間==,點擊按鈕開始查詢,

做好的控制面板如下:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.