2

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?

  • Is this during a full page postback, or an Ajax postback? If its Ajax, and you are using the radajaxmanager or radajaxproxy, make sure your control is in the updated controls list. – Obsidian Phoenix Aug 18 '13 at 21:36
  • @ObsidianPhoenix Its occuring during the full page postback... I m not using any radajaxmgr or prxy –  Aug 18 '13 at 21:43
  • Is anything presented on the UI? Do you have any markup rendered? – Jeff Fritz Aug 19 '13 at 03:32
  • Your code seems to be working when I try it here. You could try using `ddl.AppendDataBoundItems();`, see if that makes any difference. RadCombo is a fairly old version of the controls though (it's RadComboBox in newer versions of Telerik), so it could be some bug in the older version - depending on exactly how old the version you have is). – Obsidian Phoenix Aug 19 '13 at 07:37
  • Try throwing an Exception or whatever after the ddl.Items.Insert line to see what the item count is on the ddl. Lets first double check that's not empty. – Lucky Pierre Aug 20 '13 at 17:58

2 Answers2

1

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.

talegna
  • 2,407
  • 2
  • 19
  • 22
0

remove DropdownListHeight and test again