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

Radcombo Multi Select and Load On Demand

15 Answers 826 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
avarndel
Top achievements
Rank 1
avarndel asked on 08 Aug 2008, 01:55 PM
I am using the multi select in a Radcombobox from the code library.  Because the list is really long (800 +) enteries, I would also like to implement the Load on Demand.  How can I accomplish this?

Thanks,
Av

15 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 11 Aug 2008, 02:19 PM
Hello avarndel,

Please find attached a sample project demonstrating how to achieve this.
Download it and give it a try.

I hope this helps.

Regards,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
avarndel
Top achievements
Rank 1
answered on 11 Aug 2008, 03:12 PM
If I change the Onclick of the checkbox, then I can't run the multi-select code.  Because the mulit-select is slowing down my page, I only want the user to see 5-10 names at a time.  Notice I'm using a Stored Procedure to populate the dropdown.


Here is my code:

<script type="text/javascript">

var supressDropDownClosing = false;

function OnClientDropDownClosing(sender, eventArgs)

{

eventArgs.set_cancel(supressDropDownClosing);

}

function OnClientSelectedIndexChanging(sender, eventArgs)

{

eventArgs.set_cancel(supressDropDownClosing);

}

function OnClientDropDownOpening(sender, eventArgs)

{

supressDropDownClosing =

true;

}

function OnClientBlur(sender)

{

supressDropDownClosing =

false;

sender.toggleDropDown();

}

function getItemCheckBox(item)

{

//Get the 'div' representing the current RadComboBox Item.

var itemDiv = item.get_element();

//Get the collection of all 'input' elements in the 'div' (which are contained in the Item).

var inputs = itemDiv.getElementsByTagName("input");

for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)

{

var input = inputs[inputIndex];

//Check the type of the current 'input' element.

if (input.type == "checkbox")

{

return input;

}

}

return null;

}

//---------------------------Admin Assistant

function checkboxClick()

{

collectSelectedItems();

}

function collectSelectedItems()

{

var combo = $find("<%= ddlAdminAssistant.ClientID %>");

var items = combo.get_items();

var selectedItemsTexts = "";

var selectedItemsValues = "";

var itemsCount = items.get_count();

for (var itemIndex = 0; itemIndex < itemsCount; itemIndex++)

{

var item = items.getItem(itemIndex);

var checkbox = getItemCheckBox(item);

//Check whether the Item's CheckBox) is checked.

if (checkbox.checked)

{

selectedItemsTexts += item.get_text() +

", ";

selectedItemsValues += item.get_value() +

", ";

}

}

selectedItemsTexts = selectedItemsTexts.substring(0, selectedItemsTexts.length - 2);

selectedItemsValues = selectedItemsValues.substring(0, selectedItemsValues.length - 2);

//Set the text of the RadComboBox with the texts of the selected Items, separated by ','.

combo.set_text(selectedItemsTexts);

//Set the comboValue hidden field value with values of the selected Items, separated by ','.

document.getElementById(

"<%= comboValue.ClientID %>").value = selectedItemsValues;

//Clear the selection that RadComboBox has made internally.

if (selectedItemsValues == "")

{

combo.clearSelection();

}

}


<

div>

<input id="comboValue" runat="server" type="hidden" value="" /><telerik:RadComboBox ID="ddlAdminAssistant"

runat="server" AllowCustomText="True" DataSourceID="sdsAssistants" DataTextField="UserName" DataValueField="UserID"

Height="100px" HighlightTemplatedItems="True" OnClientBlur="OnClientBlur" OnClientDropDownClosing="OnClientDropDownClosing"

OnClientDropDownOpening="OnClientDropDownOpening" OnClientSelectedIndexChanging="OnClientSelectedIndexChanging"

EnableLoadOnDemand="True" ShowMoreResultsBox="True" OnItemsRequested="ddlAdminAssistant_ItemsRequested" EnableVirtualScrolling="true">

<CollapseAnimation Duration="200" Type="OutQuint" />

<ItemTemplate>

<asp:CheckBox ID="CheckBox" runat="server" onclick="checkboxClick();" Text='<%# DataBinder.Eval(Container, "Text") %>' /></ItemTemplate>

</telerik:RadComboBox>

</div>

0
avarndel
Top achievements
Rank 1
answered on 13 Aug 2008, 06:24 PM
Can't I use the datasource/Sp that is already attached to the ComboBox? I'm not sure how to implement it when the datasource is a stored Procedure. 

thx

0
Accepted
Veselin Vasilev
Telerik team
answered on 14 Aug 2008, 12:00 PM
Hi avarndel,

I guess when you click on a checkbox the dropdown is closing. To prevent this and leave the dropdown opened you need to add the following code to the checkboxClick method:

function checkboxClick(e) 
    e.cancelBubble = true
    if (e.stopPropagation) 
    { 
        e.stopPropagation(); 
    } 
 
  collectSelectedItems(); 

Make sure you send the event variable to the method as well:

<asp:CheckBox ID="CheckBox" runat="server" onclick="checkboxClick(event);" ... 

I have modified my project so now it uses SqlDataSource and a Stored Procedure for selecting the items.
Please download it and give it a try.
Note that it requires SQL Express Server to attach the database. There is a stored procedure called "Mail_GetName"  which selects the Name column from the Mail table.

Sincerely yours,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
avarndel
Top achievements
Rank 1
answered on 19 Aug 2008, 07:39 PM
Thanks that worked Perfect!

How do I set which checkbox to have checked?

Annette
0
Veselin Vasilev
Telerik team
answered on 22 Aug 2008, 01:54 PM
Hi avarndel,

I am afraid I could not understand your question.

You can get the checked items in the following way:

        Label1.Text = "Currently checked items: <br />";  
 
        foreach (RadComboBoxItem item in RadComboBox1.Items)  
        {  
            CheckBox chk = item.FindControl("CheckBox1"as CheckBox;  
            if (chk.Checked)  
            {  
                Label1.Text += item.Text + "<br />";  
            }  
        } 

I hope that this is what you asked for.

Greetings,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
eitan
Top achievements
Rank 1
answered on 14 Sep 2009, 01:19 PM
Hi there!
it seems that when working with the Radcombobox in "LoadOnDemand'" and "multi select " checkbox template, the items in the combo in all postback clears.

example:

 protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        foreach (RadComboBoxItem item in this.RadComboBox1.Items)
        {
            CheckBox checkBox = (CheckBox)item.FindControl("CheckBox");

            if (checkBox.Checked)
            {
                checkedItems.Add(item.Text);
            }
        }
        

    }

the .RadComboBox1.Items is 0.

any idea??

Thanks

Eitan.

0
avarndel
Top achievements
Rank 1
answered on 14 Sep 2009, 11:30 PM
Confirm that you have EnableViewState="True" on the page directive.
0
eitan
Top achievements
Rank 1
answered on 15 Sep 2009, 06:41 AM
Hi
Is there a way to bypass this issue without enabling the viewstate?
My app requires that the page is without viewstate.

Thanks

Eitan.
0
Vesko
Top achievements
Rank 2
answered on 17 Sep 2009, 07:32 AM
The items are not accessible on the server when EnableLoadOnDemand is True. That is why the RadComboBox1.Items is null.

http://www.telerik.com/help/aspnet-ajax/load-on-demand-access-items-server-side.html
0
Esther Nirmala
Top achievements
Rank 1
answered on 27 Apr 2010, 12:25 PM
Hi,

    AM creating the rad combo with check box dynamically from code behind.. If i click the combo item its displaying the item text.. I dont want that as i set the the empty text "Select One" to retain even if i click the item or check the check box.. if i check the check box it doesnot change the empty message.. if i click the item (which is label here) its displaying the  item as selected.. even if i simply use check box also its happening if i click outside the checkbox that is on text.. how to solve this.. soln..?

thanks
nimmi
0
Yash
Top achievements
Rank 1
answered on 19 May 2011, 04:24 PM
Can anyone tell me how to implement the same functionality when using a WebService to implement loadonDemand??
0
Kate
Telerik team
answered on 24 May 2011, 03:11 PM
Hi Yash,

Did you take a look at our online demo that explains fully how to implement Web Service load on demand? Please take a look at it and let me know if this complies with your scenario or if I am missing something. 

Greetings,
Kate
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Yash
Top achievements
Rank 1
answered on 24 May 2011, 03:20 PM
Yes I implemented the load On Demand functionality. But how is multiselect enabled in there??

regards
Yash
0
Kalina
Telerik team
answered on 26 May 2011, 04:27 PM
Hi Yash,

As I understand – you want to implement RadComboBox with LoadOnDemand via Web Service and implement a multi select scenario. Usually this scenario can be created using the control ItemTemplate – as is demonstrated here.

I am afraid that the server-side Templates are not supported when you use a Web Service to populate RadComboBox with data.
However you can use both LoadOnDemand and Templates at the same time - please take a look at this example.

Greetings,
Kalina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
ComboBox
Asked by
avarndel
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
avarndel
Top achievements
Rank 1
eitan
Top achievements
Rank 1
Vesko
Top achievements
Rank 2
Esther Nirmala
Top achievements
Rank 1
Yash
Top achievements
Rank 1
Kate
Telerik team
Kalina
Telerik team
Share this question
or