ASPX 网页的 CheckComboBox
ASPX 网页的 CheckComboBox
如何使用
它非常易于使用。只需按照以下步骤操作
- 提供一个
DataTable
,该表的第一列名为“Text
”,第二列名为“Value
”,作为其DataSource
通过设置其“
SelectedValue
”属性的值字符串来设置其选定的项目,并且该值字符串以逗号分隔- 右键单击以选择全部或不选择任何项目,同样也适用于
dropdownlist
中没有文本的第一个checkbox
- 单击以隐藏所有展开的菜单,除了光标所在的菜单
需要的文件有三个:
- CheckComboBox.ascx.cs
- CheckComboBox.ascx
- Yan.js
以下是示例代码:
// set its DataSource and Binding.
DataTable dt0 = new DataTable();
dt0.Columns.Add("Text", System.Type.GetType("System.String"));
dt0.Columns.Add("Value", System.Type.GetType("System.String"));
for (int i = 0; i < 100; i++)
{
DataRow dr = dt0.NewRow();
dr[1] = i.ToString();
dr[0] = ((char)('A' + i)).ToString();
dt0.Rows.Add(dr);
}
CheckComboBox1.DataSrc = dt0;
// get its selected values
Response.Write("
Control 1
Checked Value=" + CheckComboBox1.SelectedValue);
// set its selected items
CheckComboBox1.SelectedValue = "1,11,111";
// clear its selected items
CheckComboBox1.SelectedValue = "";
// if you want to hide all expanded menu of CheckComboBox by click,
// you must provide all id of CheckComboBox in the page
// and invoke the HideAllMenu() JavaScript method, as the following HTML code.
...
<body onclick="HideMenu()">
...
</body>
<script language="javascript">
function HideMenu()
{
var arrDD = new Array("CheckComboBox1", "CheckComboBox2");
HideAllMenu(arrDD);
}
</script>
</html>