using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
namespace QC_Control
{
/// <summary>
/// 自定义可输入下拉框类
/// </summary>
[ToolboxData("<{0}:CustomInputDropdownControl runat=server></{0}:CustomInputDropdownControl>")]
public class CustomInputDropdownControl : TextBox
{
private DropDownList ddlListItem = new DropDownList(); //下拉框
private TextBox TxtBox = new TextBox();
private Hashtable _values = new Hashtable(); //用于绑定下拉框框的值
/// <summary>
/// 键值引用变量set/get封装方法
/// </summary>
public Hashtable Item
{
get {
if (ViewState["Values"] == null)
{
ViewState["Values"] = new Hashtable();
}
else { }
Hashtable s = (Hashtable)ViewState["Values"];
return s;
}
set { ViewState["Values"] = value; }
}
/// <summary>
/// default constructor
/// initialization DropDownList and Hashtable instance variable
/// </summary>
public CustomInputDropdownControl()
{
// this._values = new Hashtable();
// this.ddlListItem = new DropDownList();
}
/// <summary>
/// 重写控件类Render方法体
/// </summary>
/// <param name="output"></param>
protected override void Render(HtmlTextWriter output)
{ ddlListItem.ID ="Ddl"+ base.ID;
TxtBox.ID ="Txt"+ base.ID;
// 框架的开始
output.Write("<table cellspacing='0' cellpadding='0' border='0'><tr><td align='left'><span style='position:absolute;border:1pt solid #c1c1c1;overflow:hidden;width:188px;height:19px;clip:rect(-1px 190px 190px 170px);'>");
//此处之所以用clientID是因为当在卡片选项时,.net程序会将base.ID自动命名名字
ddlListItem.Attributes.Add("onChange", getFocusValue(TxtBox.ID, ddlListItem.ID));
ddlListItem.Attributes.Add("style", "width:190px;height:23px;margin-top:-2px;");
TxtBox.Attributes.Add("style", "width:170px;height:15px;border:0pt;");
//遍历数据到下拉框对象中
if (this.Item.Count > 0)
{
foreach (string key in Item.Keys)
{
ListItem item = new ListItem();
item.Value = key;
item.Text = Item[key].ToString();
ddlListItem.Items.Add(item);
}
}
ddlListItem.RenderControl(output);
output.Write("</span><span style='position:absolute;border-top:1pt solid #c1c1c1;border-left:1pt solid #c1c1c1;border-bottom:1pt solid #c1c1c1;width:170px;height:19px;'>");
TxtBox.RenderControl(output);
// 框架的结尾
output.Write("</span> </td></t></table>");
}
//响应事件方法
public string getFocusValue(string TxtId,string ddlId)
{
return "javas"+"cript:"+"document.getElementById('" + TxtId + "').value=document.getElementById('" + ddlId + "').options[document.getElementById('" + ddlId + "').selectedIndex].value;".ToString();
}
}
}
分享到:
相关推荐
自定义 控件开发 asp.net控件 复合控件
.net 工业控件 .net 工业控件 .net 工业控件
vb.net DataGridView控件用法,.net DataGridView控件用法,GridView用法
.net日期控件.net日期控件.net日期控件.net日期控件.net日期控件.net日期控件.net日期控件
ASP.Net TextBox控件只允许输入数字的几种方法
Asp.net 验证码控件Asp.net 验证码控件Asp.net 验证码控件
ASP.NET服务器控件与组件开发电子书及示例代码ASP.NET服务器控件与组件开发电子书及示例代码ASP.NET服务器控件与组件开发电子书及示例代码ASP.NET服务器控件与组件开发电子书及示例代码ASP.NET服务器控件与组件开发...
vb.net 自定义控件 自定义属性 UITypeEditor UI 类型编辑器 实例 提供一个示例 UITypeEditor,它使用 IWindowsFormsEditorService 显示用于用户输入的 Form。 IWindowsFormsEditorService 只能通过 PropertyGrid ...
ASP.NET 服务器控件:DropDownCheckBoxList ,支持下拉多选,支持.NET3.5 支持主流浏览器IE8及以上版本 FF3.5+,Chrome 9+,Safari 5 等浏览器。
1、熟练掌握ASP.NET服务器控件的使用。 2、熟练掌握验证控件的使用。 二、实验内容 1、编写一个Web应用程序Login,该程序用于检查用户登录信息。当用户输入正确的用户名和密码时,显示登录成功的消息。否则,显示...
很好的C# ASP.NET下拉控件,直接导入DLL就OK了
尝试将VB.NET自定义控件的背景色设置为透明,且不遮住下面的控件。
asp.net基础控件技巧教程asp.net基础控件技巧教程asp.net基础控件技巧教程asp.net基础控件技巧教程asp.net基础控件技巧教程asp.net基础控件技巧教程asp.net基础控件技巧教程asp.net基础控件技巧教程asp.net基础控件...
网上找来的,非原创。内含控件dll和完整的调用示例。
关于ASP.NET 服务器控件之实现验证控件的介绍
.net用户控件 asp.net用户控件简单的实现用户控件
自定义等待服务器控件,提示和确认控件,进度条控件等.
.NET 菜单控件,.net控件,菜单控件,工具栏控件,vs.net控件
如何ASP.NET中开发复合控件?--vs2003,如何ASP.NET中开发复合控件?--vs2003