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

Difference of RadComboBox Text and SelectedValue properties

7 Answers 1093 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Zin-Mar
Top achievements
Rank 1
Zin-Mar asked on 03 Aug 2011, 03:43 AM
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


7 Answers, 1 is accepted

Sort by
0
STEVEN
Top achievements
Rank 1
answered on 03 Aug 2011, 06:46 AM
Just to add to this question, we are asking about both the setting of value as well as getting the value.
0
Shinu
Top achievements
Rank 1
answered on 03 Aug 2011, 07:15 AM
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.
0
Princy
Top achievements
Rank 1
answered on 03 Aug 2011, 07:25 AM
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.
0
STEVEN
Top achievements
Rank 1
answered on 03 Aug 2011, 07:34 AM
Thanks for the fast response.

What about setting the value for the combo box at page load?
Should we set the Text or SelectedValue?
0
Princy
Top achievements
Rank 1
answered on 03 Aug 2011, 08:32 AM
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
0
Nuno
Top achievements
Rank 1
answered on 06 Sep 2013, 02:39 PM
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?
0
Shinu
Top achievements
Rank 1
answered on 09 Sep 2013, 03:33 AM
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.
Tags
ComboBox
Asked by
Zin-Mar
Top achievements
Rank 1
Answers by
STEVEN
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Nuno
Top achievements
Rank 1
Share this question
or