This is a migrated thread and some comments may be shown as answers.
Selecting items in code behind
3 Answers 127 Views
This is a migrated thread and some comments may be shown as answers.
Paweł Aszklar
Top achievements
Rank 1
Paweł Aszklar asked on 12 Aug 2009, 10:00 AM

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

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 20 Aug 2009, 07:21 AM
Hello Paweł Aszklar,

The issue described is a bug in the RadListBox. Fortunately, we have fixed it. You can check on the latest internal build.

Regards,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paweł Aszklar
Top achievements
Rank 1
answered on 25 Aug 2009, 09:52 AM
Hi Genady Sergeev,

Thanks for the reply.

I downloaded internal build (version 2009.2.824) but it did not fix the problem. I after postback all items are selected again unless I do one of the magic tricks I described before. I have also tried to write some javascript to select items on the client side and I got the same effect. I can post my javascript sample, but i would be quite a lot of code since i needed to use webservices and stuff.

I hope to hear from you soon. Thanks in advance.

Regards
Paweł Aszklar
0
Accepted
Genady Sergeev
Telerik team
answered on 28 Aug 2009, 12:10 PM
Hi Paweł Aszklar,

I have managed to reproduce the issue, it is really bug in the RadListBox. Fortunately, we were able to fix it fast. You can find the the issue fixed forth from the next week's internal build. In addition I have updated your Telerik points for the bug report.

All the best,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Asked by
Paweł Aszklar
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Paweł Aszklar
Top achievements
Rank 1
Share this question
or