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

selectindex when binding to sqldatasource

1 Answer 49 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Liu Yan
Top achievements
Rank 1
Liu Yan asked on 28 Aug 2008, 05:25 AM

I am binding to a SqlDatasource which contains tow fileds 'name' and 'val', when PageLoad,I hope to select one of the items via 'val' value.but it's not work. here is my code:

int index = RadComboBox3.FindItemIndexByValue(reader.GetString(4).ToString().Trim());
RadComboBox3.SelectedIndex = index;

do you have good idears? thanks

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 28 Aug 2008, 06:50 AM
Hello Liu Yan,

Have you set the DataValueField property to "val" ?
Also, you need to call RadComboBox3.DataBind() method before finding the item.
You can try also:

RadComboBox3.DataValueField = "val";
RadComboBox3.DataBind();
RadComboBox3.SelectedValue = reader.GetString(4).ToString().Trim();


Greetings,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Liu Yan
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or