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

add radcomboxitem to radcombox in clientside does not work

3 Answers 87 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Bahare
Top achievements
Rank 1
Bahare asked on 12 Oct 2012, 10:25 PM
hi, i have rad combobox in my web page that i defined it like this:
 <telerik:RadComboBox  DropDownWidth="220px" runat="server" ID="UnitCombo"> 
                    <HeaderTemplate>
                        <table cellpadding="0" width="200px" cellspacing="0">
                            <tr>
                                <td style=" width:100px" >unit</td>
                                <td style="width:100px">ReviseState</td>
                            </tr>
                        </table>
                    </HeaderTemplate>
                    <ItemTemplate>
                     <table cellpadding="0" width="200px" cellspacing="0">
                            <tr>
                                <td style=" width:100px" >
                                    <%# DataBinder.Eval(Container,"Text") %>
                                </td>
                                <td style="width:100px">
                                      <%# DataBinder.Eval(Container,"Attributes['State']") %>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </telerik:RadComboBox>

i want to add new items to this radcombo in clientside so i wrote this code:
      function updateCombo(result) {
            var UnitCombo = $find("<%= UnitCombo.ClientID %>");
            var Comitems = UnitCombo.get_items();
            Comitems.clear();
            var items = result.split('|');
            for (var i = 0; i < items.length; i++) {
                var temp = items[i].split(',');
                UnitCombo.trackChanges();
                var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                comboItem.set_text(temp[0]);
                comboItem.get_attributes().setAttribute("State", temp[1]);

                UnitCombo.get_items().add(comboItem);
                UnitCombo.commitChanges();
            }
          
        }
items add to radcombo correctly but attribute part does not show,and no script error happen also
items in radcombo just show Unit part....
please help me..thanks

3 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 17 Oct 2012, 03:21 PM
Hello Bahare,

As I can see, from the provided snippet of code, you correctly add new RadComboBoxItem along with the custom attributes at client side. Please make sure that the values assigned to the custom attributes are correct. I have prepared a sample project for you, covering your scenario. Find the sample attached.

Greetings,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Bahare
Top achievements
Rank 1
answered on 18 Oct 2012, 10:40 AM
hi,thanks for replying ,but there is point here, i use this control in a webform which open in radwindow and i don't want to use any post back to bind data to radcombobox as you do ,i mean you use DataBind() in your PageLoad event and when you comment this part, your code doesn't work correctly and the same scenario happen to your control:"empty item"
so what should i do to make all this happen in clientside in my javascript code?in other words can i use DataBind Method in client side because pageLoad Event Doesn't fire in my case when i add item to my radcombo box and i should bind data in another Place,and i check my code with fix string as you have done but the same problem happened again and it means there is no problem with contain of my strings
please guide me
thanks

0
Nencho
Telerik team
answered on 23 Oct 2012, 07:17 AM
Hello Bahare,

In order to fit the requirements of your scenario, you should use a ClientItemTemplate and invoke the bindTemplate() client side method. Thus you will not need to fire a PostBack to bind the ItemTemplates, because the binding would be handled at client side. I have slightly modified the sample, in order to implement the aforementioned approach.


Greetings,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Bahare
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Bahare
Top achievements
Rank 1
Share this question
or