- Name CheckList
- CSS Class table.CC_CheckList, tr.rh, tr.r[n], tr.rn, tr.Selected, col.cb, colgroup.cg, col.c[n], col.cn
- Types int Index, string Value, string Text, string Checked
New in 0.8.1
The CheckList creates a tabular list of Text strings, each having a hidden
Value string associated with it. It is not intended to grow into a full
Grid but can have a Checkbox column enabled, and even have per-row or
header-row buttons attached directly. Allowing you to add (for example)
Button.Click() events that fire on the server.
It can however be overloaded to show a simple grid view. Any tab characters
( "\t" in C# ) in the Title property or any of the row Texts will be
used to split the row into columns. Because Chan aims to be both flexible and lightweight
it is up to you to police these strings for undesired tabs
and assert that each row has the same number as the Title.
Because Chan (unlike standard ASPX) does not have a built in viewstate
the CheckList will forget its contents whenever the page is loaded or
posted back. For this reason you will need to populate it in Page_Init().
However you are free to inherit from the CheckList and
use its own Control.Init() to populate it with a set series of values,
for example.
CSS Styling
The CheckList comes with built-in basic styling but tries to allow
flexibility via the list of class names above.
- The table is table#[ID], where ID is the id given to the CheckList control
- The table is also table.CC_CheckList
- The header row is tr.rh
- The header row cells and all button/checkbox cells are th
- The button/checkbox cells are in their own colgroup col.cb
- All data cells share a colgroup.cg
- All data cells have a single column each as col.c[n], where n is the index of the data-column
- The right-most data cell is also col.cn, for browsers that do not support :last-child
- All data cells' rows are tr.r[n], where n is the index of the data-row
- The bottom-most data row is also tr.rn, for browsers that do not support :last-child
- If the CheckList is of CheckBox or Radio type then any checked rows will also be tr.Selected
| Qualifiers |
Type |
Name |
Default |
Description |
|
string |
id |
"" |
Unique identifier within the page for the control |
|
bool |
Visible |
true |
Wether or not the control is rendered into the page's HTML. |
|
bool |
Encode |
true |
Wether or not the Row-Text and Title properties of the list are Html-Encoded, when false you can set each row's text to contain literal html, e.g. inserting links. |
|
string |
Type |
"list" |
One of "list","checkbox" and "radio" which correspond to a basic list, a list with a column of checkboxes (with built in Select All and None buttons in the header) and a list with a column of radios. |
|
string |
Checked |
"" |
This allows you to get or set the Checked state of all the rows in the list. When type="checkbox" it uses a comma-seperated (not CSV escaped!) string of Values. So if you have a list containing four items with values 1,2,3 and 4 and you set Checked="2,3" then the middle two will be checked, you can set this to "*" to select all or "" to select none. For type="radio" it only accepts and returns a single value and the "" overload. |
|
string |
Clicked |
"" |
The row Value that is currently the target of a row-button Click event, if any. |
|
List |
Buttons |
(empty) |
This allows you to bind buttons to the list by creating them and calling Buttons.Add( MyButton ), with one then being automatically spawned by Chan for each row, they will behave exactly like normal Chan buttons, including client and server OnClick and Click events, respectively. When handling Click() on the server you will be able to reference the CheckList's Clicked property to read which row's button was clicked. The string of the button's onclick javascript can have the following qualifiers inserted [Text],[Value] and [Index] and these will be set to the relevant values for each row (In the case of a multi-column Text string the leftmost column will be used). |
|
List |
HeadButtons |
(empty) |
This allows you to bind buttons to the list as per Buttons but these will be shown in the top header row above any row buttons. |
| Qualifiers |
Type |
Name |
Params |
Description |
|
|
Add |
(string Text) |
Add an item to the list, this overload creates an entry where the Value is the same as the Text |
|
|
Add |
(string Value , string Text) |
Add an item to the drop down, this overload can be used to create "null" entries by setting Value to "" |
|
|
Add |
(object Value , object Text) |
Add an item to the drop down, this overload automatically calls ToString() on the passed in objects, and treats null and DBNull as "" |
|
|
RemoveAll |
() |
Removes all items from the list |
|
|
Remove |
( string value ) |
Removes the item with the given value from the list, if it exists. |
|
|
RemoveAt |
( int index ) |
Removes the item at the given index from the list, if the index is out of bounds an exception will NOT be thrown |
|
string |
ValueAt |
( int index ) |
Returns the string Value at the given index, an invalid index will return "" |
|
string |
ValueOf |
( string text ) |
Returns the string Value corresponding to the given Text, returns "" if the text does not exist in the list |
|
string |
TextAt |
( int index ) |
Returns the string Text at the given index, an invalid index will return "" |
|
string |
TextOf |
( string value ) |
Returns the string Text corresponding to the given Value, returns "" if the value does not exist in the list |
|
int |
IndexOfValue |
( string value ) |
Returns the index of to the given Value, returns -1 if the value does not exist in the list |
|
int |
IndexOfText |
( string text ) |
Returns the index of to the given Text, returns -1 if the text does not exist in the list |
This live demo illustrates the effect of the code as shown in the Example
tab but may be altered slightly to fit in with this site's own operating
environment.
Because this is a simple demo if you delete two in a row the first one will reappear!