您的位置:首页 > 编程语言 > ASP

一个实现查询功能的asp.net控件

2006-10-22 14:42 746 查看
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="  ";
}
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);
}
}
}
}

主要实现功能是,在文本框中输入查询内容,下拉框中可选择查询查询范围,比如分类,时间==,点击按钮开始查询,

做好的控件外观如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐