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

webservice & selectedValue

7 Answers 161 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Piyush Bhatt
Top achievements
Rank 2
Piyush Bhatt asked on 10 Apr 2008, 08:10 PM
I am trying to use the WebService to populate my drop down.

Now, when I show the dropdown first time I need to show a selected item. What is the recommended way of doing that? because setting selectedValue does not have any effect because there is not data bound to it from server side!!

Thanks,
Piyush

7 Answers, 1 is accepted

Sort by
0
Piyush Bhatt
Top achievements
Rank 2
answered on 10 Apr 2008, 09:41 PM
One way I did it was setting the Text property while loading the page.

The other problem I am facing now is:
- I set the SelectedValue from the code behind
- I used keyboard to delete the content of combo box to indicate that no value is selected
- I postback - the post back event remembers the original Selected Value and on the server side I don't know if the value is unselected! My AllowCustomText is set to False.

0
Nikolay
Telerik team
answered on 11 Apr 2008, 11:27 AM
Hello Piyush,

You could hook on the OnClientItemsRequested event that is fired right after the items have been populated. There, you can find the needed item and select it using the client-side object model of the combobox:

function OnClientItemsRequested(sender, args)
{
     var combo = sender;
     var neededItem = combo.findItemByText("text");
     neededItem.select();
}

Hope this helps.

Sincerely yours,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Piyush Bhatt
Top achievements
Rank 2
answered on 11 Apr 2008, 01:42 PM

The OnClientItemRequesting will get called when I click on the combo box or type something in. So, this wouldn't work.

I have to display the form with selected value. Currently I am setting Text property from the code behind.

-Piyush
0
Alan Johns
Top achievements
Rank 1
answered on 16 Apr 2008, 01:27 AM
What is the best practice here?

When you populate a form from a database and show the user the values in the load-on-deman dropdowns, where do you store the value from the database? I can show the Text in the combobox to the user, that's no problem. I was using the .value property with the older radControls to store this, but it's been removed from the Prometheus version.

It's possible the user will not touch the combobox and the OnClientItemsRequested event will never get fired. In this case, where's the value of this combobox supposed to come from when the user submits the data back to the server? It won't be in selectedvalue...

Thanks,

-Alan
0
Nikolay
Telerik team
answered on 16 Apr 2008, 06:47 AM
Hi there,

Piyush, I meant the OnClientItemsRequested event, not the OnClientItemsRequesting. The OnClientItemsRequested event is fired when the items have been completely loaded.


Alan , the SelectedValue property of the combobox Prometheus should now return the selected value even in a callback mode. Did you mean that the SelectedValue property is empty at the server side?

Regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Piyush Bhatt
Top achievements
Rank 2
answered on 16 Apr 2008, 02:18 PM
Nick,

When a page is rendered, if the user has not clicked on the drop down, will OnClientItemRequested() get called?

One may have 1000 items in database. And web-service would return only (for better performance) 10 or 20 as per what user types in. Now, how following would work if web-service won't even return that item?

var neededItem = combo.findItemByText("text");

Another - the selected value is actually on the server side. So, we would have to put it into some other control to make it available on the client side and then use above method.

Also, it needs to be selected only when the page renders first time and not after user selects some other item from the drop down. So, we would have to check using javascript whether this is first time or whether user has selected some different value already.

Don't you think this would be too much? I like to set the initial selected value and text property from code behind when page renders. Hopefully it should be the right practice according to telerik.

-Piyush
0
Nikolay
Telerik team
answered on 17 Apr 2008, 10:37 AM
Hello Piyush,

You will not be able to select any item if no items have been previously added to the combobox. You can, however, set some text to the input field when the page is first rendered. For example, you can use the pageLoad event and set some default text to the input part of the combobox, like:

<script>
   function pageLoad()
   {
        var comboBox = $find("<%=RadComboBox1.ClientID"%>);
        comboBox.set_text("text");
   }

</script>

Additionally, you can set the default text only if the items have not been loaded yet:

if(comboBox.get_items().get_count()==0)
{
   comboBox.set_text("text");
}

I hope that this is acceptable for you.

Kind regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Piyush Bhatt
Top achievements
Rank 2
Answers by
Piyush Bhatt
Top achievements
Rank 2
Nikolay
Telerik team
Alan Johns
Top achievements
Rank 1
Share this question
or