65.9K
CodeProject 正在变化。 阅读更多。
Home

ASPX 网页的 CheckComboBox

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.22/5 (2投票s)

2007年1月4日

CPOL
viewsIcon

127127

downloadIcon

240

ASPX 网页的 CheckComboBox

Sample Image - CheckComboBox_for_web.jpg

如何使用

它非常易于使用。只需按照以下步骤操作

  1. 提供一个 DataTable,该表的第一列名为“Text”,第二列名为“Value”,作为其 DataSource
  2. 通过设置其“SelectedValue”属性的值字符串来设置其选定的项目,并且该值字符串以逗号分隔
  3. 右键单击以选择全部或不选择任何项目,同样也适用于 dropdownlist 中没有文本的第一个 checkbox
  4. 单击以隐藏所有展开的菜单,除了光标所在的菜单

需要的文件有三个:

  1. CheckComboBox.ascx.cs
  2. CheckComboBox.ascx
  3. 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>
© . All rights reserved.