1

I have Telerik RadComboBox ,

    <telerik:RadComboBox runat="server" ID="comboTown" Width="150px">
    </telerik:RadComboBox>

And I bind this table

Town
-----
TownOne
TownTwo
TownThree
TownFour

to comboTown show as below

  comboTown.DataSource = DB.Towns.ToList();
  comboTown.DataTextField = "Town";
  comboTown.DataValueField = "Town";

But , when I set selectedValue for comboTown likes comboTown.SelectedValue= "TownTwo";

I get this error message
Selection out of range
Parameter name: value

I want to know why , what am i doing wrong?

zey
  • 5,939
  • 14
  • 56
  • 110

2 Answers2

1

Before

comboTown.SelectedValue= "TownTwo"

add code

comboTown.DataBind()

Eugene
  • 325
  • 1
  • 5
0

I just tried this and it worked for me :

Mark Up:

<telerik:RadComboBox runat="server" ID="comboTown" Width="150px" />
<telerik:RadButton runat="server" ID="btnSetSelectedValue" 
 OnClick="btnSetSelectedValue_Click"></telerik:RadButton>

Code:

 protected void Page_Load(object sender, EventArgs e)
 {
    if (!IsPostBack)
    {
       comboTown.DataSource = new List<string> { "TownOne", 
                                                 "TownTwo", 
                                                 "TownThree", 
                                                 "TownFour" 
                                               };
            comboTown.DataBind();
    }
 }

 protected void btnSetSelectedValue_Click(object sender, EventArgs e)
 {
        comboTown.SelectedValue = "TownThree";
 }

As you can see - I have a combo box. On page load if it is not a postback I bind it to values. I have a button and on click of button I do a postback and set a selected value on combo box to "TownThree". This worked for me.

kashyapa
  • 1,606
  • 1
  • 10
  • 13