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

Getting the SelectedValue after setting the SelectedItem.Text Programmatically

1 Answer 66 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Brent
Top achievements
Rank 1
Brent asked on 07 Oct 2008, 03:23 PM
This has to be a very simple request, but I just started using your RAD Ajax ASP combo box...

I have a combobox that is bound to a list of States.
- I am setting the DataValueField to an integer that is basically an identity value in the database.
- I am setting the DataTextField to the abbreviations of the State.

When a user fills out the form and saves the data to a database, we are saving the DataTextField , not the value field.  So, we'd save "NC" or "NY" for instance, instead of the integer of 37 or 39 or whatever corresponds to that state. 

BTW:  After the user selects a state, I use the SelectedValue to find a list of Counties that belong to that state.

Here is what I don't know how to do:
- In our app, the user can pull up this data to edit it.  Since they have previously selected a State, I need to select the value of the state that they had chosen, in the Combobox.

Q.  How can I do that?  I fill the combo box with a list of States, but if I set the "SelectedItem.Text" to the state abbreviation that they had chosen, it obviously sets the text of the first item in the combobox to their state. 
But that is wrong.  I want to programmatically select the state that they had selected, in the combox box.

- Since I only have the State abbreviation (the DataTextField) and
not the ID, I can't set the "SelectedValue" (if that would even do what I want).

I guess the question boils down to:  If I have a combo box full of string values, how can I programmatically select an item from the combo box, based on that string value?

Thanks,
Brent

1 Answer, 1 is accepted

Sort by
0
Brent
Top achievements
Rank 1
answered on 07 Oct 2008, 05:25 PM
I've figured it out.  Sorry to ask such a novice level question...  Using:

RadComboBoxItem

StateRadComboBoxItem = this.StateDropDownList.FindItemByText(debtor.State);

 

 

if (StateRadComboBoxItem != null)

 

{

StateRadComboBoxItem.Selected =

true;

}

 

Tags
ComboBox
Asked by
Brent
Top achievements
Rank 1
Answers by
Brent
Top achievements
Rank 1
Share this question
or