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

  • 相关阅读:
    最新pear安装
    php垃圾收集机制
    strstr的实现
    PHP 快速生成目录树
    php 去掉字符串
    php批量生成mysql触发器定义语句
    HTML的知识点讲解(HTML版本)
    mysql数据库怎么使用,mysql的使用方法
    sublime text3Emmet:HTML/CSS代码快速编写神器
    图片滚动插件jquery bxslider
  • 原文地址:https://www.cnblogs.com/insus/p/2263185.html
Copyright © 2011-2022 走看看