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

RadCombo SelectedValue in SelectedIndexChanged

14 Answers 615 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Doug Odegaard
Top achievements
Rank 2
Doug Odegaard asked on 24 Mar 2008, 10:19 PM
    protected void ddlMake_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
    {  
        ViewState["Make"] = e.Text;  
    } 

Forgive me if this is an extremely easy question but for some reason I cannot get the SelectedValue rather than the SelectedText from the RadCombo in the SelectedIndesChanged event.  Can someone please help me find where this may be?  e.Text is the only thing that appears to be accessible.  My ID values are the hidden piece I need.

Thanks in advance.
Doug

14 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 25 Mar 2008, 04:17 PM
Hello Doug Odegaard,

Please try using RadComboBox.SelectedValue property in the event handler to get the value of the currently selected item.

Please let me know how it goes.

Sincerely yours,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Doug Odegaard
Top achievements
Rank 2
answered on 25 Mar 2008, 04:21 PM
It returns a null.  I am using this with your LoadOnDemand demo example.  I basically need to get the underlying value once someone has chosen a value.  All I can see is that it is very "display text" centric.

Thanks.
Doug
0
Steele
Top achievements
Rank 1
answered on 25 Mar 2008, 07:02 PM
I need this functionality as well...

I would expect the RadComboBoxSelectedIndexChangedEventArgs to include .Text, .Value and .Index properties at the least.

.SelectedIndex() is essential in my understanding of how to make synchronized comboboxes work properly via AJAX.

If I had a selected Index collection, I could use the NeedsDataSource to rely on the data being populated during the ajax call, even if it is reloaded.

Having support for Multiselection, i.e. SelectedIndex() instead of .SelectedIndex is important as well.

to further expand on this...

I have a radComboBox on a Master Page.
The Master Page has a RadAjaxManager
The radComboBox is set to AutoPostBack=True
The AjaxManager is set so that FacilitySelector Updates FacilitySelector

This code does not work...

Private Sub FacilitySelector_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles FacilitySelector.SelectedIndexChanged

Dim cbo = TryCast(o, Telerik.Web.UI.RadComboBox)

If cbo IsNot Nothing Then

Try

If Session("FacilityUID") <> CInt(cbo.SelectedValue) Then

Session("FacilityUID") = CInt(cbo.SelectedValue)

End If

Catch ex As Exception

End Try

End If

End Sub


The FIRST time it does in fact work, it sets the sessionvar and updates the control.

Subsequent Changes do NOT work because the SelectedIndex is always the same, the first item selected.

I have tried setting EnableViewState both ways, and various other things but I cannot access he newly selected item after the first selection.

I DO NOT want to do this with JavaScript, this should be a server-side function that works with AjaxManager.

e.Text is Correct showing the newly selected text and so does the following code, but this just seems like a Kludge since e.Text is not considered Unique (but in fact "most likely is" in my particular case).

Private Sub FacilitySelector_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles FacilitySelector.SelectedIndexChanged

Dim cbo = TryCast(o, Telerik.Web.UI.RadComboBox)

If cbo IsNot Nothing Then

Try

Dim item As Integer = cbo.FindItemIndexByText(e.Text)

cbo.SelectedIndex = item

If Session("FacilityUID") <> cbo.SelectedValue Then

Session("FacilityUID") = cbo.SelectedValue

End If

Catch ex As Exception

End Try

End If

End Sub

0
Simon
Telerik team
answered on 28 Mar 2008, 01:30 PM
Hi Steele,

We have already planned the implementation of the RadComboBox's Value as a property of the SelectedIndexChanged event arguments. However, the addition of the Index property needs further consideration.

Now, to your specific case. I created a sample project using the configuration you have described. It worked as expected. Please see the attached project for a reference.

Best wishes,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Doug Odegaard
Top achievements
Rank 2
answered on 31 Mar 2008, 08:14 PM
Any date on the implementation of the Value property??  Looks like it was part of the ASP.NET Controls RadCombo previously based on the documentation.
0
Nikolay
Telerik team
answered on 03 Apr 2008, 11:28 AM
Hi Doug Odegaard,

Our developers will surely include this property in the forthcoming Q1 release due by the end of this month. I hope this timeframe is acceptable for you.

Regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Doug Odegaard
Top achievements
Rank 2
answered on 03 Apr 2008, 11:51 AM
Sounds perfect to me.  I crearted a wild workaround until it is posted.  Thanks Nick!
0
Kishan A
Top achievements
Rank 1
answered on 26 Oct 2009, 03:12 PM
Hi,
    I am in similar situation where in I need the value of the selected item. Is there anyupdates on this?
"RadcomboBox.SelectedValue" gives the text but not the corresponding value.
0
Casey
Top achievements
Rank 1
answered on 26 Oct 2009, 04:06 PM

Kishan,

Are you trying to find the value during the SelectedIndexChanged event? If so, I find that the below code works for me to return the newly selected value. Also, you may want to ensure that your DataValueField is setup to be the field you wish to return. It sounds like maybe your DataValueField and DataTextField properties are setup to be against the same field from the datasource.

 

protected void RadComboBox1_SelectedIndexChanged(object source, RadComboBoxSelectedIndexChangedEventArgs e)  
    {  
        string comboValue = e.Value;  
    } 

I hope this helps,
Casey
0
Kishan A
Top achievements
Rank 1
answered on 27 Oct 2009, 02:57 AM
Hey Casey,
    Thanks a ton!!I'm relieved.....It worked!!!!
Cheers,
Kishan
0
Pravallika
Top achievements
Rank 1
answered on 16 Jun 2014, 05:31 AM
its not working for me radcombobox1.text is working means corresponding text is coming but e.value is not coming and in debugging value is showing empty
0
Shinu
Top achievements
Rank 2
answered on 16 Jun 2014, 08:29 AM
Hi Pravallika,

Such an issue is not expected, please make sure that you have mentioned the Value for the items in the RadComboBox. Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadComboBox ID="rcboCountry" runat="server" EmptyMessage="--select--" DataSourceID="SqlDataSource1" AutoPostBack="true" DataTextField="CountryName" OnSelectedIndexChanged="rcboCountry_SelectedIndexChanged" DataValueField="CountryId">
</telerik:RadComboBox>

Please provide your full code if it doesn't help.
Thanks,
Shinu.
0
Pravallika
Top achievements
Rank 1
answered on 16 Jun 2014, 08:39 AM
<telerik:RadComboBox ID="cmbItemMaster" Width="90%"  AutoPostBack="true" runat="server"
                                      AllowCustomText="true" Filter="Contains" EmptyMessage="select" OnSelectedIndexChanged="cmbItemMaster_SelectedIndexChanged"
                                    ></telerik:RadComboBox>
 
 protected void LoadItemMaster()
       {
           cmbItemMaster.DataSource = objItemMasterDAO.GetAllItemMasters();
           cmbItemMaster.DataValueField = "ItemMasterID";
           cmbItemMaster.DataTextField = "ItemMasterName";
           cmbItemMaster.DataBind();
       }
protected void cmbItemMaster_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
       {
           if (e.Value != "")
           {
               LoadItemMaster(e.Value);
           }
      }
when i wrote cmbItemMaster.Text  here i am getting the value but in e.value showing null
0
Shinu
Top achievements
Rank 2
answered on 17 Jun 2014, 03:48 AM
Hi Pravallika,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadComboBox ID="rcboItems" runat="server" AllowCustomText="true" Filter="Contains"
    EmptyMessage="select" AutoPostBack="true" OnSelectedIndexChanged="rcboCountry_SelectedIndexChanged">
</telerik:RadComboBox>

C#:
protected void Page_init(object sender, EventArgs e)
{
    rcboItems.DataSource = GetData();
    rcboItems.DataValueField = "ItemMasterID";
    rcboItems.DataTextField = "ItemMasterName";
    rcboItems.DataBind();
}
protected DataTable GetData()
{
    DataTable dtcboItems = new DataTable();
    dtcboItems.Columns.Add(new DataColumn("ItemMasterID"));
    dtcboItems.Columns.Add(new DataColumn("ItemMasterName"));
 
    dtcboItems.Rows.Add(new object[] { 1, "Canada" });
    dtcboItems.Rows.Add(new object[] { 2, "Saudi Arabia" });
    dtcboItems.Rows.Add(new object[] { 3, "Mexico" });
    dtcboItems.Rows.Add(new object[] { 4, "Venezuela" });
 
    return dtcboItems;
}
protected void rcboCountry_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
    string selectedValue = e.Value;
}

Thanks,
Shinu.
Tags
ComboBox
Asked by
Doug Odegaard
Top achievements
Rank 2
Answers by
Simon
Telerik team
Doug Odegaard
Top achievements
Rank 2
Steele
Top achievements
Rank 1
Nikolay
Telerik team
Kishan A
Top achievements
Rank 1
Casey
Top achievements
Rank 1
Pravallika
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or