惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
IT之家
IT之家
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42
爱范儿
爱范儿
博客园 - 聂微东
F
Fortinet All Blogs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
雷峰网
雷峰网
B
Blog RSS Feed
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - ansonpan

戒烟第五天! 戒烟第二天! 戒烟第一天! 扩展fckeditor的上传图片和上传文件功能! (二) 翟鸿燊-《国学应用大智慧》笔记 Sage Accpac ERP 销售订单模块激活问题! Asp.net 团队博客地址 SQL2000游标引发的性能问题! datalist嵌套TreeView 收发邮件的一些心得。 数组遍历判断两个输入框之间是否有输入重复的值! - ansonpan - 博客园 SQL2005分页查询语句! 控制一个登录名只能访问一个数据库! ASP.NET网站安装部署参考总结! Visual Studio 2008 Web部署项目插件下载 验证视图状态 MAC 失败 扩展fckeditor的上传图片和上传文件功能! 喝酒的五个阶段! 打开网页要输入用户名和密码的解决方案!
匹配下拉控件
ansonpan · 2008-02-16 · via 博客园 - ansonpan

因为之前看到人家的一个匹配下拉控件,做得好酷,所以自己也开发了一个,虽然现在还比较丑陋,但还是能用的,还有很多不方便的地方要修改,所以源码就先不公布了。
先看看效果:

我点文本框的绿色图标,它会自动给我显示下拉项。

当我输入一个中字,它会自动匹配到凡是中字开头的项而显示出来。

基本上现在这个控件能达到这样的效果,可能用起来不是很方便有待改善,用时需要一个文本框,一个隐藏按钮控件,然后再拖拽这个匹配控件出来设置几个属性即可。
匹配控件的实现:
新建一个类,继承

WebControl。开始定义控件的属性。

[System.ComponentModel.NotifyParentProperty(true)]
        [Description(
"要匹配的控件的ID号")]
        [TypeConverter(
typeof(ValidatedControlConverter))]
        [DefaultValue(
"")]
        
public string MatchTextBoxID
        
{
            
get
            
{
                
string s = (string)ViewState["MatchTextBoxID"];
                
return (s == null? "" : s;

            }

            
set
            
{
                ViewState[
"MatchTextBoxID"= value;
            }

        }



        [System.ComponentModel.NotifyParentProperty(
true)]
        [Description(
"存储匹配的控件值的ID号")]
        [TypeConverter(
typeof(ValidatedControlConverter))]
        [DefaultValue(
"0")]
        
public string MatchTextBoxValueID
        
{
            
get
            
{
                
string s = (string)ViewState["MatchTextBoxValueID"];
                
return (s == null? "0" : s;

            }

            
set
            
{
                ViewState[
"MatchTextBoxValueID"= value;
            }

        }

重写呈现控件的方法

 protected override void OnPreRender(EventArgs e)
        {
            if (Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "IwoakTextBoxMatch") == false)
            {

                this.Page.ClientScript.RegisterClientScriptInclude(
           this.GetType(), "TextBoxMatch",
           Page.ClientScript.GetWebResourceUrl(this.GetType(),
           "Iwoak.Controls.TextBoxMatch.js"));
            }

            base.OnPreRender(e);
        }

 protected override void Render(HtmlTextWriter writer)

{
。。。。。。。。。。。。
}

再新建一个js

//****************
//可输可选可匹配输入的控件类
//参数(高,文本框的ID,隐藏控件的ID用于保存选择的ID值,图片的路径)
//****************

function TextMatch(Height, TextMatchText,TextMatchValue,imgurl)
{
    var TextMatchObject = this; 
 if(imgurl !="")
     TextMatchObject.img = imgurl; 
 
 var TextMatchDiv = document.createElement('div');
 var TextMatchFrame = document.createElement('iframe');
 var TextMatchButton = document.createElement('input');

TextMatchDiv.style.position = 'absolute';
TextMatchFrame.style.zIndex = '100';
 TextMatchFrame.src = 'javascript:void(0)';

设置TextMatchDiv,TextMatchButton ,TextMatchFrame ,的样式.......................

  //关闭选项层
 function hideTextMatch(e)
 {
  e = (e == null) ? window.event : e;
  target = (e.target) ? e.target : e.srcElement;
     TextMatchDiv.style.display = 'none';
   TextMatchFrame.style.display = 'none';
  
 }

//展开匹配层
 function showTextMatch()

{
。。。
}
//注册事件
xtMatchText.addEventListener('keyup', function(){showMatch()}, false);
  TextMatchButton.addEventListener('click', function(){showTextMatch()}, false);
  window.addEventListener('click', function(e){hideTextMatch(e)}, false);

}
基本上就完成了。
别人的更牛,选了之后输入框都可以有图片和链接的,不知道到他的“文本框”是用什么组合实现的。
放出他的效果图给大家瞧瞧。

我觉得这个效果可以,下个阶段目标就是要实现这个。有兴趣的朋友可以交流交流。