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

RadComboBox - LoadOnDemand and Setting Initital Value/Text

11 Answers 658 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Angelo Babudro
Top achievements
Rank 1
Angelo Babudro asked on 04 Feb 2008, 06:33 PM
I have several RadCombo boxes (latest install of Prometheus) on a screen that I wish to use for editing and adding new orders. I am using LoadOnDemand (via RadComboBox1_ItemsRequested) to populate the combo boxes with data from a SQL server database.  However when editing an existing order how do I display the existing values in the database? The LoadOnDemand doesn't kick off until you actually access the combo box... I have seen several of the online demos that Telerik staff say to reference but none of them work...They say that LoadOnDemand dos not have any notion of binding or selecteditem/selectedvalue. They say instead to use the .Value and .Text property...however there is no such property as .value

To further complicate things several combo boxes are dependent on one another...i.e. select something from one combo box and the items in the second are "filtered"

Any help would be appreciated.

11 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 05 Feb 2008, 08:02 AM
Hi Ashley Murray,

With RadComboBox Prometheus you should be able to use the SelectedValue property to obtain the value of the selected item even in a callback mode. What does the SelectedValue property return in your case?

To set an initial value/text you can use the set_value and set_text methods of the combobox objects. You can hook on the client-side onload event of the page (<body onload="...">) and call the methods in the event handler.

Kind regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Angelo Babudro
Top achievements
Rank 1
answered on 05 Feb 2008, 11:18 AM
Nick:

The problem isn't returning the selected value the problem is setting it... Becuase I am using LoadOnDemand=True, when the page first loads the combo box is empty until I click the drop down and then the items are retrieved. All is well and good at that point...I can select a value and move on. However this same form is not only used to add new orders but is also used to view existing orders. So now the page is hit with an orderid in the querystring. I grab that, retrieve the order and want to display it. So now how do I set the value and text in the combo box so the user can see it and then change it if required? For example a combo box might be for displaying countries...

Country ID        Country Text
1                       USA
2                        Canada
3                        Mexico

You mention using javascript...can you please provide a small sample app?

Thank you.
0
Veselin Vasilev
Telerik team
answered on 06 Feb 2008, 02:42 PM
Hi Ashley Murray,

As you want to use QueryString you can do something like this:

protected void Page_Load(object sender, EventArgs e) 
    if (!IsPostBack) 
    { 
        if (Request.QueryString["orderID"] != null
        { 
            RadComboBox1.Text = Request.QueryString["orderID"].ToString(); 
        } 
    } 


I hope this helps.

Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Angelo Babudro
Top achievements
Rank 1
answered on 06 Feb 2008, 03:03 PM
Yes setting the text is certainly no problem. But its the associated datavalue (i.e. Key id that is the problem). According to some of your posts there is supposed to be a RadComboBox1.Value property but no such property exists.

I need to be able to set both the Key id value and the text value because as with a fully normalized database it's the Key value that is actually stored with the record and the text comes from a lookup table.

Thank you.
0
Veselin Vasilev
Telerik team
answered on 06 Feb 2008, 03:23 PM
Hi Ashley Murray,

You can also set the SelectedValue property of the combobox to the appropriate value (ID)

// set the SelectedValue to the appropriate ID  
RadComboBox1.SelectedValue = Request.QueryString["orderID"].ToString(); 

To summarize: when you get the orderID you can set the Text and the SelectedValue of the Combobox.


Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Kyle
Top achievements
Rank 1
answered on 29 Oct 2008, 08:49 PM
I am experiencing pretty much the same problem in the latest version of the RadCombo.  I have a RadCombo with loadondemand enabled.  On page load the selectedvalue is set to a particular value.  In this case it is an account code.  However, nothing displays in the radCombo because none of the accounts have been loaded.  If I click the drop arrow, the control loads.  If I then click away from the control to make the control loose focus, the selected value is now showing the correct text.  I realize that I can set the text manually on the page load, however we are trying to reduce sql calls whenever possible.  Being supplied with just the account code, I do not want to have to go look up the account name via sql just to set the text on the control.  I realize this is more of an inherent design flaw of load on demand.  Is there a better work around then just doing a manual lookup?

Thanks,
Kyle
0
Veselin Vasilev
Telerik team
answered on 03 Nov 2008, 03:35 PM
Hi Kyle,

With load-on-demand enabled, the items of the combobox are not added initially. You need to do something (click the dropdown or call the requestItems method) to add the items to the control. The combobox has no idea what is the text of the item if it knows only the SelectedValue and the items are not loaded as in your case. So, you need to do a query to get the text of the selected item and set it as a text of the combobox.

Kyle, can you explain in more detail what is your scenario?

Greetings,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Craig Corbin
Top achievements
Rank 1
answered on 05 Oct 2009, 05:32 PM
Even in the latest version (at the time of writing) of the RadCombo, the tooltip for the RadCombo.SelectedValue only describes the getter and not the setter.  Regardless, the setter is there and it does work.

I used the following to get an initial value to display...

RadCombo.SelectedValue = EmployeeId;

RadCombo.Text = EmployeeName;

Craig

0
EJ
Top achievements
Rank 1
answered on 21 Jul 2010, 07:17 PM
is there a way to do this using declarative databinding (e.g. Bind() in markup) rather than manage it manually like this?
0
Cat Cheshire
Top achievements
Rank 1
answered on 22 Jul 2010, 09:39 AM

If you use RadComboBox with load on demand  - for example in EditItemTemplate of FormView - you cannot declaratively set the SelectedValue (SelectedValue ='<%#Bind("something") %>').
The same is for GridView or RadGrid “Edit” templates.

This happens because when such combo is loaded on the page - there are no items in it. The control requests its items when you click/write in the input,  or click on the arrow (in case there are no items loaded).
This is the way load on demand works.

You can hook the DataBound event, create manually and preselect one item or simply set the Text and SelectedValue in the combo.
0
Kanna
Top achievements
Rank 2
answered on 04 Apr 2012, 10:38 AM
Hi, Me too had the same issue with RadCombo when using LoadOnDemand.

The solution Mr. Cat Cheshire suggested is working fine.
Just assign text property and followed by SelectedValue property of radCombo in that case.

Thanks,
Santhosh
Tags
ComboBox
Asked by
Angelo Babudro
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Angelo Babudro
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Kyle
Top achievements
Rank 1
Craig Corbin
Top achievements
Rank 1
EJ
Top achievements
Rank 1
Cat Cheshire
Top achievements
Rank 1
Kanna
Top achievements
Rank 2
Share this question
or