使用系统;
使用system.collections.generic;
使用system.componentmodel;
使用system.text;
使用的system.web;
使用system.web.ui程序;
使用system.web.ui.webcontrols;
system.collections中使用;
命名空间qc_control
{
///
///自定义可输入下拉框类
/// 摘要>
[toolboxdata(“ {0}:custominputdropdowncontrol>”) ]
公共类custominputdropdowncontrol:文本框
{
私人dropdownlist的ddllistitem =新的dropdownlist(); //下拉框
的私人文本框txtbox =新的textbox();
私人hashtable的_values =新的hashtable(); //用于绑定下拉框框的值
///
///键值引用变量设置/获取封装方法
/// 摘要>
公开hashtable的项目
{
获得{
如果(的viewstate [“值”] = = null)
{
的viewstate [“值”] =新的hashtable();
}
其他{}
hashtable的s =(哈希表)的viewstate [“值”];
返回s;
}
设置{的viewstate [“值”] =值; }
}
///
///默认构造函数
///初始化的dropdownlist和hashtable实例变量
/// 摘要>
公开custominputdropdowncontrol()
{
// this._values =新的hashtable();
// this.ddllistitem =新的dropdownlist();
}
///
///重写控件类渲染方法体
/// 摘要>
/// param>的
保护覆盖无效渲染(htmltextwriter的输出)
{ddllistitem。 id =“ddl”+ base.id;
txtbox.id =“txt」+ base.id;
//框架的开始
output.write(“
//此处之所以用clientid的是因为当在卡片选项时,.net程序会将base.id自动命名名字
ddllistitem.attributes.add(“的onchange”,getfocusvalue(txtbox.id,ddllistitem.id));
ddllistitem.attributes.add(“风格”,“宽度:190px; family:宋体;的margin-top:-2px;”);
txtbox.attributes.add(“风格”,“宽度:170像素,高度:15px的;边框:0pt;”);
//遍历数据到下拉框对象中
,如果(this.item.count> 0)
{
的foreach(字符串item.keys键)
{
列表项项=新的listitem();
item.value =键;
item.text =项目[关键]的tostring();
ddllistitem.items.add(项目);
}
}
ddllistitem.rendercontrol(输出);
output.write(“ span>的”);
txtbox.rendercontrol(输出);
//框架的结尾
output.write(“ span> td> t> table>”);
}
//响应事件方法
公共字符串getfocusvalue(字符串txtid,串ddlid)
{
回归“java类”+“cript:”+“的document.getelementbyid('”+ txtid +“').value的=的document.getelementbyid('”+ ddlid +“')可供选项[的document.getelementbyid('”+ ddlid +“').selectedindex] .value的;”的tostring();
}
}
}









