Issues setting SelectedValue on Page_Load()

5 posts, 0 answers
  1. Jason Thacker
    Jason Thacker avatar
    18 posts
    Member since:
    Apr 2009

    Posted 24 Aug 2010 Link to this post

    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,
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 24 Aug 2010 Link to this post

    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.
  3. Jason Thacker
    Jason Thacker avatar
    18 posts
    Member since:
    Apr 2009

    Posted 24 Aug 2010 Link to this post

    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.
  4. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 24 Aug 2010 Link to this post

    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.
  5. Jason Thacker
    Jason Thacker avatar
    18 posts
    Member since:
    Apr 2009

    Posted 24 Aug 2010 Link to this post

    Thanks Cori, I figured it out. It was an ID10T error on my part in a completely unrelated bit of code!
Back to Top