zoukankan      html  css  js  c++  java
  • 搜索功能

    首先看看效果:

    文本框与搜索铵钮放在母版页(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);
        }
    }

    Masterpage按钮事件,需要把page转换为接口:

    View Code
     protected void Button1_Click(object sender, EventArgs e)
        {
            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;
        }
    }

    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;
        }
    }

    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;
            }
        }
    }

    源程序:

     http://download.cnblogs.com/insus/ASPDOTNET/Search.rar

  • 相关阅读:
    多IDC数据分布--MySQL多机房部署
    Mongodb~连接串的整理
    Jenkins~配合Docker及dotnetCore进行生产和测试环境的灵活部署
    jenkins~集群分发功能的具体实现
    DotNetCore跨平台~linux上还原自主nuget包需要注意的问题
    jenkins~集群分发功能和职责处理
    HDU 2074 叠筐
    破解Veeam过程
    hdu1015(Safecracker )
    Oracle—RMAN备份(一)
  • 原文地址:https://www.cnblogs.com/insus/p/2263185.html
Copyright © 2011-2022 走看看