Asp.net可输入下拉框服务器控件 C#版

//备注:改自Ryan Liu (dpliu@cbdsystem.com.cn)vb.net
using System;
using System.Collections;
using System.ComponentModel; 
using System.Web.UI; 
using System.Web.UI.Design; 
using System.Web.UI.WebControls; 

namespace CBDAspNet.WebControls.HTML 

[ToolboxData("<{0}:TextBox runat=/"server/" />")
public class TextBox : System.Web.UI.WebControls.TextBox 

private Hashtable _values; 
public DropDownList _DropDownList; 

public TextBox() 

_DropDownList = new DropDownList(); 
_values = new Hashtable(); 


public Hashtable Values 

get 

return _values; 

set 

_values = value; 



protected override void Render(System.Web.UI.HtmlTextWriter Output) 

int iWidth = Convert.ToInt32(base.Width.Value); 
if (iWidth == 0) 

iWidth = 102; 

int sWidth = iWidth + 16; 
int spanWidth = sWidth - 18; 
Output.Write("<div style=/"POSITION:relative/">")
Output.Write("<span style=/"MARGIN-LEFT:" + spanWidth + "px;OVERFLOW:hidden;WIDTH:18px/">")
_DropDownList.Width = Unit.Parse(sWidth + "px")
_DropDownList.Style.Add("MARGIN-LEFT", "-" + spanWidth + "px")
_DropDownList.Attributes.Add("onchange", "this.parentNode.nextSibling.value=this.value")
if (_values.Count > 0) 

foreach (string key in _values.Keys) 

ListItem item = new ListItem(); 
item.Value = key; 
item.Text = _values[key].ToString(); 
_DropDownList.Items.Add(item); 



//如果只有一个可选内容
if (_DropDownList.Items.Count == 1) 

ListItem item = new ListItem(); 
item.Value = ""; 
item.Text = " "; 
_DropDownList.Items.Add(item); 
_DropDownList.SelectedIndex = 1; 

_DropDownList.RenderControl(Output); 
Output.Write("</span>")
base.Style.Clear(); 
base.Width = Unit.Parse(iWidth + "px")
base.Style.Add("left", "0px")
base.Style.Add("POSITION", "absolute")
base.Render(Output); 
Output.Write("</div>")


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值