Hi,
I have two listbox controls both having SelectionMode="Multiple". First one is populated from object data source. Selecting an item in the first listbox causes the SelectedIndexChanged event to fire, where I populate the second one and select all items in it. Then I select an item in the second listbox in a browser and click a button (or cause any other postback). After that all items in the second listbox are selected again. I've found two ways to select something other than all items.
1. Selecting items while holding ctrl key seems to work, but it's not very handy.
2. In the second listbox moving the scrollbar, selecting an item and then causing postback gets all items unselected (even the one just selected). Then selecting works as expected.
here is my asp sample:
<div style="float: left; width: 150px"> | |
<asp:Label ID="_lblBrokerLabel" runat="server" Text="Pośrednik:" /><br /> | |
<telerik:RadListBox ID="_rlbBrokers" runat="server" DataSourceID="_odsBrokers" DataTextField="Name" | |
DataValueField="ID" Skin="Default" AutoPostBack="true" CausesValidation="false" | |
SelectionMode="Multiple" OnSelectedIndexChanged="BrokersChanged" Height="200" /> | |
<asp:RequiredFieldValidator ControlToValidate="_rlbBrokers" Text="*" ID="_rfvBrokers" | |
runat="server" /> | |
<asp:ObjectDataSource ID="_odsBrokers" runat="server" SelectMethod="GetUserBrokers" | |
TypeName="Ewita.Model.Entities"> | |
<SelectParameters> | |
<asp:Parameter Name="userId" Type="Int32" /> | |
<asp:Parameter Name="activeOnly" Type="Boolean" DefaultValue="False" /> | |
</SelectParameters> | |
</asp:ObjectDataSource> | |
</div> | |
<div style="float: left; width: 150px"> | |
<asp:Label ID="_lblWarehouseLabel" runat="server" Text="Magazyny:" /><br /> | |
<telerik:RadListBox ID="_rlbWarehouses" runat="server" DataValueField="ID" Skin="Default" | |
SelectionMode="Multiple" Height="200"> | |
<ItemTemplate> | |
<asp:Panel CssClass='<%# (bool)Eval("Active")?"":"inactive" %>' ID="_pnlWarehouse" | |
runat="server"> | |
<%# Eval("Name") %> | |
</asp:Panel> | |
</ItemTemplate> | |
</telerik:RadListBox> | |
<asp:RequiredFieldValidator ControlToValidate="_rlbWarehouses" Text="*" ID="_rfvWarehouses" | |
runat="server" /> | |
</div> |
and here is code behind
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (IsPostBack) return; | |
var user = (User)Session["user"]; | |
_odsBrokers.SelectParameters["userId"].DefaultValue = user.ID.ToString(); | |
} | |
protected void BrokersChanged(object sender, EventArgs e) | |
{ | |
var warehouses = new List<Warehouse>(); | |
var user = (User)Session["user"]; | |
foreach (var item in _rlbBrokers.SelectedItems) | |
{ | |
int brokerId; | |
if (!int.TryParse(item.Value, out brokerId)) continue; | |
warehouses.AddRange(Entities.Instance.GetUserWarehouses(brokerId, user.ID, false)); | |
} | |
_rlbWarehouses.DataSource = warehouses; | |
_rlbWarehouses.DataBind(); | |
foreach (RadListBoxItem item in _rlbWarehouses.Items) | |
{ | |
item.Selected = true; | |
} | |
} |
I checked this issue on Opera and Firefox browsers. I'm using .net 3.5, visual studio 2008 and Telerik RadControls for ASP.NET Ajax v. 2009.2.701.35
Thanks in advance.Regards
Paweł Aszklar