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

Issues setting SelectedValue on Page_Load()

4 Answers 90 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jason Thacker
Top achievements
Rank 1
Jason Thacker asked on 24 Aug 2010, 01:52 PM
I hope that this will be an easy problem to solve! I have the following ComboBox in my page:

<telerik:RadComboBox ID="rcbLocation" runat="server" AllowCustomText="True" DataSourceID="sdsLocation" DataTextField="Location_Name" DataValueField="Location_ID" MarkFirstMatch="True">
</telerik:RadComboBox>

And in Page_Load() I attempt to set the value as follows (the DataBind is just there to make sure!):

rcbLocation.DataBind();
rcbLocation.SelectedValue = ReturnedData["Master_Location"].ToString();

However, even though the SelectedValue on the ComboBox is set, the Text is blank and the SelectedIndex appears to have a value of "-1".

Am I doing something incredibly stupid here, or am I required to perform some kind of work-around (as opposed to how I may handle a DropDownList, for example)? Having read other threads, I have also tried setting the SelectedIndex using the FindItemIndexByValue functionality, but this doesn't seem to work either.

Any help would be appreciated. Thanks,

4 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 24 Aug 2010, 02:03 PM
Hello Jason,

What does your DataSource look like, does it require some parameter to be passed, which your not passing? Or try turning off AllowCustomText and see if that fixes the issue.

That's all I can think off, since you are calling DataBind on the combobox so the data should be there.
0
Jason Thacker
Top achievements
Rank 1
answered on 24 Aug 2010, 02:07 PM
There are no parameters on the datasource, it is a simple SELECT statement.

Unfortunately I need the AllowCustomText option to be set, disabling it is not an option, unless there is another way to get the same functionality.
0
Cori
Top achievements
Rank 2
answered on 24 Aug 2010, 04:04 PM
Have you stepped through your code and checked that control has its items set and that the SelectedValue executed correctly?

I don't know what else I can say.
0
Jason Thacker
Top achievements
Rank 1
answered on 24 Aug 2010, 04:44 PM
Thanks Cori, I figured it out. It was an ID10T error on my part in a completely unrelated bit of code!
Tags
ComboBox
Asked by
Jason Thacker
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Jason Thacker
Top achievements
Rank 1
Share this question
or