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

  • 相关阅读:
    kafka_consumer3->spark_master
    为什么.NET感觉上比Java差一点
    学习Scala: 初学者应该了解的知识
    函数式编程 : 一个程序猿进化的故事
    Scala underscore的用途
    不变(Invariant), 协变(Covarinat), 逆变(Contravariant) : 一个程序猿进化的故事
    Scala Collection简介
    C# on Visual Studio Code
    我的Machine Learning学习之路
    Scala on Visual Studio Code
  • 原文地址:https://www.cnblogs.com/insus/p/2263185.html
Copyright © 2011-2022 走看看