Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CheckComboBox for ASPX web

0.00/5 (No votes)
3 Jan 2007 4  
CheckComboBox for ASPX Web

Sample Image - CheckComboBox_for_web.jpg

How to use

It is very easy to use. Just follow the steps given below:

  1. Provide a DataTable, which has the first column named "Text" and the second column named "Value", as its DataSource
  2. Set its checked items by setting the value string of its "SelectedValue" property, and the value string is divided by comma
  3. Right click to select all or none, so do the first checkbox without text in dropdownlist
  4. Click to hide all expanded menu, except for the one on which the cursor is

The three required files are:

  1. CheckComboBox.ascx.cs
  2. CheckComboBox.ascx
  3. Yan.js

The sample code is given below:

// 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>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here