This is a migrated thread and some comments may be shown as answers.

Retain server-side selection on dropdown close

2 Answers 26 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Simeon
Top achievements
Rank 1
Simeon asked on 15 Nov 2018, 12:58 PM

Hello guys,

We have a ComboBox with checkboxes that is populated in the server-side. Also there it is determined which items should be checked. AutoPostBack for the component is set to false and we trigger a postback through other means.

When the dropdown is closed (OnClientDropDownClosing or OnClientDropDownClosed event), we need to retain the items that were checked at the last postback.

Here is an example:

Let's say we have the items a,b,c,d in the ComboBox:

a and b are set to checked at the last postback. On the client-side the user makes some changes so that yet c and d are checked. Now he decides to close the dropdown. We want that yet a and b are left checked.

 

Currently we have that implemented through a "hack", but we have some cases with massive thata(2000 items+) where it takes several seconds before the dropdown closes, and this is a major performance issue. So is there any way to implement that behaviour?

 

Thanks,

Simeon

 

2 Answers, 1 is accepted

Sort by
0
Simeon
Top achievements
Rank 1
answered on 16 Nov 2018, 12:18 PM

Hi again,

so the problem seems to be the set_checked() method of the combobox item. It is really slow. Is there at least a faster alternative to that?

Thanks,

Simeon

0
Peter Milchev
Telerik team
answered on 20 Nov 2018, 11:59 AM
Hello Simeon,

You can achieve something similar on the server, where the performance should be better. 

protected void RadComboBox1_Load(object sender, EventArgs e)
{
    if (ViewState["previouslyCheckedItemsIndices"] != null)
    {
        var checkedItemsIndices = (int[]) ViewState["previouslyCheckedItemsIndices"];
        foreach (int index in checkedItemsIndices)
        {
            RadComboBox1.Items[index].Checked = true;
        }
    }               
}
 
protected void RadComboBox1_PreRender(object sender, EventArgs e)
{
    ViewState.Add("previouslyCheckedItemsIndices", RadComboBox1.GetCheckedIndices());
}

<telerik:RadButton runat="server" ID="RadButton1" Text="Postback" AutoPostBack="true" />
<telerik:RadComboBox ID="RadComboBox1" OnPreRender="RadComboBox1_PreRender" OnLoad="RadComboBox1_Load"
    CheckBoxes="true" runat="server" RenderMode="Lightweight">
    <Items>
        <telerik:RadComboBoxItem Text="Item 1" />
        <telerik:RadComboBoxItem Text="Item 2" />
        <telerik:RadComboBoxItem Text="Item 3" />
        <telerik:RadComboBoxItem Text="Item 4" />
    </Items>
</telerik:RadComboBox>

Regards,
Peter Milchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Simeon
Top achievements
Rank 1
Answers by
Simeon
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or