1

How can I get my CheckBoxList to have three possible states ? More precisely, is there a way to have three possible states for each checkbox : checked, unchecked, undefined (in most GUIs this is represented as a full square).

Alternatively, do you recommend another control that would meet these needs ?

UPDATE : Ok, given that HTML does not support tri-state checkboxes, I'm looking for a way to 'CSS' (color fill, highlight, etc...) the checkboxes of the items that are in that 'undefined' state from my server point of view.

BuZz
  • 16,318
  • 31
  • 86
  • 141
  • how about a dropdown? – user1 May 21 '13 at 16:45
  • Not easily as the checkbox is rooted in HTML heritage. Check this for alternative solutions: http://stackoverflow.com/questions/1726096/tri-state-check-box-in-html or this: http://www.codeproject.com/Articles/20159/ASP-NET-TriState-CheckBox-Made-Easy – Simon Mourier May 21 '13 at 16:46
  • How about if you use Javascript? http://shamsmi.blogspot.co.uk/2008/12/tri-state-checkbox-using-javascript.html – Matthew Watson May 21 '13 at 16:46

4 Answers4

5

Not all GUIs represent undefined as a full square. That's why it's going to be clearer to use one of the following:
1. Radio boxes
2. Dropdown
3. ListBox

RAS
  • 3,375
  • 15
  • 24
2

Any asp.net control you use will ultimately need to be rendered as an html checkbox, which can only be checked or unchecked. You could use a data- attribute to keep track of extra state behind the scenes, but that wouldn't be reflected in the UI.

I suppose you could also implement a client-side solution using JavaScript and CSS as well.

Jason P
  • 26,984
  • 3
  • 31
  • 45
2

You could just extend or derive from the CheckBoxList and create your own custom control from it.

Here is an example of this.

Custom CheckBoxList

James Leshko
  • 173
  • 1
  • 3
  • 16
0

I have decided to use CheckBoxList anyway, since I need two states accessible by the user, and a third one not accessible by the user but to display inconsistencies.

The way I have solved this is through Javascript + CSS. Some bits of ideas here: http://css-tricks.com/indeterminate-checkboxes/

BuZz
  • 16,318
  • 31
  • 86
  • 141