Asp.net可输入下拉框服务器控件 C#版
2006-09-21 09:51
447 查看
//备注:改自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>");
}
}
}
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>");
}
}
}
相关文章推荐
- Asp.net可输入下拉框服务器控件 C#版
- Page.RegisterStartupScript 方法 [C#]请参见允许 ASP.NET 服务器控件在 Page 中发出客户端脚本块。
- ASP.NET c# textbox 正则表达式 文本框只允许输入数字(验证控件RegularExpressionValidator )
- asp.net(c#)web服务器控件,多选框checkboxlist控件。
- ASP.NET中服务器控件Button调用javascript代码运用正则表达式验证TextBox中输入的是否为正整数或正小数,符合要求则继续运行服务器端代码功能的实现
- [ASP.NET 2.0]定制C#TextBox控件中只允许输入数字的解决方法
- asp.net+C# 服务器安装篇---示使用XSL样式表无法查看XML输入
- 允许 ASP.NET 服务器控件在 Page 中发出客户端脚本块的方法Page.RegisterClientScriptBlock 方法 [C#]
- 让服务器控件执行js与C#两种代码(asp.net)
- ASP.NET 2.0服务器控件开发的基本概念(转载)
- ASP.NET(C#)中将TextBox控件的Readonly属性设置为True时后台直接取值取不到的解决方案
- [转] c# 模拟Asp.net页面中的某个按钮的点击,向web服务器发出请求
- 用VisualC#.NET编写服务器日期控件
- 关于ASP.NET中使用服务器控件影响效率的问题
- ASP.NET MVC 扩展服务器控件使用方式
- 使用 C# 编写简易 ASP.NET Web 服务器
- ★★★【庖丁解牛:纵向切入Asp.net 3.5控件和组件开发技术--基于VS 2008(兼容VS 2005)/C#】★★★
- asp.net(C#)中给控件添加客户端js事件的方法
- asp.net控件开发基础(14) --------服务器控件生成器
- ASP.NET -TreeView Web 服务器控件事件