搜索功能
首先看看效果:
文本框与搜索铵钮放在母版页(MasterPage),每个将搜索结果显示在aspx网页上,如Label,或者是搜索网页的上的内容,如果DropDownList或是RadioButtonList等。
当然方法明白了,把处理的结果显示在GridView,DataList或是Repeater等数据控件上是没有问题。
关键的地方,Insus.NET使用了一个interface接口,因为不同对象处理不同的结果。
ISearchable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for ISearchable
/// </summary>
namespace Insus.NET
{
public interface ISearchable
{
void GetSearchWork(string str);
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for ISearchable
/// </summary>
namespace Insus.NET
{
public interface ISearchable
{
void GetSearchWork(string str);
}
}
Masterpage按钮事件,需要把page转换为接口:
View Code
protected void Button1_Click(object sender, EventArgs e)
{
ISearchable obj = (ISearchable)this.Page;
obj.GetSearchWork(this.TextBox1.Text);
}
{
ISearchable obj = (ISearchable)this.Page;
obj.GetSearchWork(this.TextBox1.Text);
}
Label.aspx.cs实现接口:
View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class Label : System.Web.UI.Page,ISearchable
{
public void GetSearchWork(string str)
{
this.Label1.Text = str;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class Label : System.Web.UI.Page,ISearchable
{
public void GetSearchWork(string str)
{
this.Label1.Text = str;
}
}
DropDownList.aspx.cs实现接口:
View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class DropDownList : System.Web.UI.Page, ISearchable
{
public void GetSearchWork(string str)
{
this.DropDownList1.SelectedValue = str;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class DropDownList : System.Web.UI.Page, ISearchable
{
public void GetSearchWork(string str)
{
this.DropDownList1.SelectedValue = str;
}
}
RadioButtonList.aspx.cs实现接口:
View Code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class RadioButtonList : System.Web.UI.Page,ISearchable
{
public void GetSearchWork(string str)
{
foreach (ListItem li in RadioButtonList1.Items)
{
li.Selected = li.Text.Contains(str) ? true : false;
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class RadioButtonList : System.Web.UI.Page,ISearchable
{
public void GetSearchWork(string str)
{
foreach (ListItem li in RadioButtonList1.Items)
{
li.Selected = li.Text.Contains(str) ? true : false;
}
}
}
源程序:
http://download.cnblogs.com/insus/ASPDOTNET/Search.rar