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

5 posts, 0 answers
  1. Nim
    Nim avatar
    43 posts
    Member since:
    Sep 2010

    Posted 06 Jan 2011 Link to this post

    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!
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 07 Jan 2011 Link to this post

    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.
  3. Nim
    Nim avatar
    43 posts
    Member since:
    Sep 2010

    Posted 07 Jan 2011 Link to this post

    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!
  4. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 07 Jan 2011 Link to this post

    Hello Nim,

    You just add a code block. Like so:

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

    I hope that helps.
  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 17 Jan 2011 Link to this post

    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.
Back to Top