Difference of RadComboBox Text and SelectedValue properties

8 posts, 0 answers
  1. Zin-Mar
    Zin-Mar avatar
    1 posts
    Member since:
    Sep 2010

    Posted 02 Aug 2011 Link to this post

    Hi Telerik Team,

    We use Telerik RadComboBox at our application.
    I would like to know when to use "Text" and when to use "Selected Value" properties for comboBox.
    What is the difference between these two properties?

    Thanks.
    best regards,
    zin mar htun


  2. STEVEN
    STEVEN avatar
    37 posts
    Member since:
    Oct 2010

    Posted 03 Aug 2011 Link to this post

    Just to add to this question, we are asking about both the setting of value as well as getting the value.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Aug 2011 Link to this post

    Hello Zin-mar,

    Text is the string that the user sees for the item in the drop-down list while Value is the value associated with the item which determines the value of the combobox SelectedValue property when the item is selected.
    For further information you can check the following help documentation Overview.

    Thanks,
    Shinu.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Aug 2011 Link to this post

    Hello Steven,

    You can access the SelectedValue in SelectedIndexChanged event of the RadComboBox
    C#:
    protected void SearchCountry_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
           string str=SearchCountry.SelectedValue;
    }
    Also check the following help documentation which explains more about this.
    SelectedIndexChanged.

    Thanks,
    Princy.
  6. STEVEN
    STEVEN avatar
    37 posts
    Member since:
    Oct 2010

    Posted 03 Aug 2011 Link to this post

    Thanks for the fast response.

    What about setting the value for the combo box at page load?
    Should we set the Text or SelectedValue?
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Aug 2011 Link to this post

    Hello Steven,

    You can set the SelectedValue in page load as shown below.
    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
           SearchCountry.SelectedValue = "Name";
    }

    Thanks,
    Princy
  8. Nuno
    Nuno avatar
    1 posts
    Member since:
    Sep 2013

    Posted 06 Sep 2013 Link to this post

    Hi.

    i'm using RadCombobox with Items loaded by a javascript function. Like in the example below,

    function FillServiceTypes(id, valuesList) {
        var i = 0;
        var servTypeComboBox = $find(id);
        servTypeComboBox.clearItems();

        var selected = false;
        $.each(valuesList, function () {
            var rcbItem = new Telerik.Web.UI.RadComboBoxItem();
            rcbItem.set_text(this['Text']);
            rcbItem.set_value(this['Value']);
            servTypeComboBox.trackChanges();
            servTypeComboBox.get_items().add(rcbItem);
            if (this['Selected']) {
                rcbItem.select();
                selected = true;
            }
            servTypeComboBox.commitChanges();
        });

        if (!selected && valuesList.length > 0) {
            servTypeComboBox.get_items().getItem(0).select();
        }
        servTypeComboBox.commitChanges();
    }

    The problem is that when i try to read the Value in server side, using the combo.SelectedValue, the result is the same of using combo.Text, the result is always the text instead of the id.

    Someone could help me to understand this behavior?
  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Sep 2013 Link to this post

    Hi Nuno,

    Please have a look at the full code that I tried to get the RadComboBox selected value in Button onclick event.

    ASPX:

    <telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientLoad="OnClientLoad1">
    </telerik:RadComboBox>
    <telerik:RadButton ID="RadButton1" runat="server" Text="GetSelectedValue"
        onclick="RadButton1_Click">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function OnClientLoad1(sender, args) {
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            comboItem.set_text("New Item");
            comboItem.set_value("Value1");
            sender.trackChanges();
            sender.get_items().add(comboItem);
            comboItem.select();
            sender.commitChanges();
        }
    </script>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        var value = RadComboBox1.SelectedValue;
        Response.Write("<script>alert('" + value + "');</script>");
    }

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017