Reputation:
I have a telerik rad combo on my form
<radC:RadCombo ID="ddl" runat="server" DropdownListHeight="200px"/>
In CS
Under another rad combo's Selected Index Changed event
var dt = myFunc();
ddl.DataTextField="Name";
ddl.DataValueField="Id";
ddl.DataSource=dt;
ddl.Databind();
ddl.Items.Insert(0,new RadComboBoxItem ("-1","---Choose---"));
Please note:
I have 25 items coming from db and the datatable dt
has only two columns, Name
and Id
as described above. No errors are thrown , everything went fine but the result is not visible on the UI.
Any insight/help?
Upvotes: 2
Views: 2522
Reputation: 2403
If you're using a RadAjaxManager/RadAjaxManagerProxy have you identified that the first drop down list will be updating the second drop down list:
<telerik:RadAjaxManagerProxy ID="ajaxManager" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="ddlWithOnChangeEvent">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="ddlBeingUpdated" />
</UpdatedControls>
</telerik:AjaxSetting>
...
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
The next point worth looking at is that you should probably set the AppendDataBoundItems to true, this will allow both data bound objects to be added to the combo box as well as those manually added.
<telerik:RadComboBox ID="ddlBeingUpdated" runat="server" Height="200px" AppendDataBoundItems="true" />
One thing which is worth pointing out here is that if you keep the function as it is, every time you databind, it will merely add the new items again to the existing list. I would suggest here that the function is changed to clear any previous items before adding new ones.
var dt = myFunc();
ddlBeingUpdated.Items.Clear();
ddlBeingUpdated.DataTextField="Name";
ddlBeingUpdated.DataValueField="Id";
ddlBeingUpdated.DataSource=dt;
ddlBeingUpdated.Databind();
ddl.Items.Insert(0,new RadComboBoxItem ("-1","---Choose---"));
I am aware, looking at your code, that my version is possibly more recent than your own but hopefully the above examples can demonstrate how you can implement the changes required.
Upvotes: 1