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

How to control which item is selected when the page is first-loaded?

4 Answers 69 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nim
Top achievements
Rank 1
Nim asked on 07 Jan 2011, 12:29 AM
Hello,

I'm building a MVC program.

In the view, I have a combo box:

    <telerik:RadComboBox ID="RadComboBox1" runat="server"
        DataSourceID="EntityDataSource1" DataTextField="data"
        DataValueField="value">
    </telerik:RadComboBox>

I can populate the combo box with a list of options provided by the database (through Entity).

Here is my question.

Say, in some situations, when the page is loaded, I want option 1 to be selected first; then in some other situations, when the page is loaded, I want a different option, say option 3, to be selected.  And say, the situation will depend on a magic number I store in the session.

Is there anyway I can control which option to be selected when a page is loaded (without using ajax call after the page is loaded)?

Also, is there any small example to demonstrate how to control which item to be selected at the beginning, in MVC environment?

Many thanks!

4 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 07 Jan 2011, 02:39 PM
Hello Nim,

If you want a certain item to be selected when the page loads, just called DataBind(0 on the RadComboBox control and then set the SelectedValue to the items you want selected.

I hope that helps.
0
Nim
Top achievements
Rank 1
answered on 07 Jan 2011, 06:39 PM
Hello,

Thank you for the tip.

I may be missing something in the documentation.

I am not sure how to use "DataBind" and "SelectedValue" in the View.

Is there any small example to demonstrate this for MVC program?

Many thanks!
0
Cori
Top achievements
Rank 2
answered on 07 Jan 2011, 08:24 PM
Hello Nim,

You just add a code block. Like so:

<% RadComboBox1.DataBind();
RadComboBox1.SelectedValue = "Some Value"; %>

I hope that helps.
0
Kalina
Telerik team
answered on 17 Jan 2011, 04:07 PM
Hi Nim,

Please note that  ASP.NET and ASP.NET MVC are two completely different frameworks.

Because of this we have created a whole new control family called Telerik Extensions for ASP.NET MVC.
I would suggest you use the Telerik ComboBox for ASP.NET MVC control instead of RadComboBox for ASP.NET AJAX.
You can find the key features of the Telerik ComboBox for ASP.NET MVC demonstrated here.

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
Nim
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Nim
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or