I must say I haven't seen anything like this on the forums, but possibly I overlooked a thread or demo. However, I am using a ListView with the following templates: LayoutTemplate, InsertItemTemplate, ItemTemplate, SelectedItemTemplate and EditItemTemplate. An item consists of a LinkButton. See example below:
<%# Eval("Value1") %><
<%# Eval("Value2") %><
<%# Eval("Value3") %><
<%# Eval("Value4") %>
where "Value#" is just a string from a certain datasource. As you can see this LinkButton has its CommandName property set to "Select". When you select a single
item, the selected item will appear using the SelectItemTemplate (that is with inversed colors as the normal ItemTemplate). But, I have a problem with (de)selecting all items.
This ListView currently contains 2 items. The LayoutTemplate holds a button to select or deselect all items in the ListView. This button is linked through the ItemCommand event ("onitemcommand") with its CommandName property set to "DeSelectAll". In my code-behind I do:
sender, RadListViewCommandEventArgs e)
RadListView rlv = sender
(rlv.SelectedItems.Count == rlv.Items.Count)
As I said the ListView currently contains 2 items. So whenever the button - to select or deselect all items - is clicked this event is fired. So when you are debugging it looks like it's working, but visually it's far from what you actually want.
Firstly (situation 1), if no item has been preselected (both items are not selected) and you click the button visually nothing happens, while under water (code) the item.Selected properties are changed accordingly. When you click the button for the second time both items change to the SelectedItemTemplate, while under water the item.Selected properties are set back to "false". Notice, you have to click twice in order to get this result.
Secondly (situation 2), if one of two items has been preselected (this works as mentioned earlier) (1) and you click the button visually nothing happens, while under water the item.Selected properties are changed accordingly (both items have their Selected property set to "true") (2). Notice that you can't see any difference visually (the preselected item still is the only visible selected item). Next, click the item - which visually still is the only selected item - and be amazed this item deselects and the other gets selected (3). To make one another clear, let's schematize this:
- item 1: selected, item 2: not selected, visibility: item 1 uses SelectedItemTemplate, item 2 uses ItemTemplate
- item 1: selected, item 2: selected, visibility: item 1 uses SelectedItemTemplate, item 2 uses ItemTemplate
- item 1: not selected, item 2: selected, visibility: item 1 uses ItemTemplate, item 2 uses SelectedItemTemplate
As you can see, step 2 is the problem. The property "Selected" for both items is set to "true", but visually item 2 is not using the correct template. Instead of using ItemTemplate it should be using SelectedItemTemplate. Notice that in both situations you have to click twice to visually get a result.
Any thoughts or suggestions on how to select or deselect all items in a ListView?
Thanks in advance.