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

Can I invoke RadCombo_Onload from another method on the client?

3 Answers 39 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 14 Feb 2013, 11:32 AM
Hi,

I'm using rad combo box within the rad grid. The combo box is populated on the client and within the combo there's an "add new item" link.
When I insert new item, the item is inserted into the database via web service but the combo box doesn't update with the new item. I think if i'm able to some how invoke or call the combo_onload client event after I've inserted the new item that this would work. So my question is can I call the combo_onload client event from another method?

function OwnerComboBox_OnLoad(sender, eventArgs) {
 
             InvoiceWebService.GetItemsByCompanyId(sessionStorage.CompanyId, OnItemsComplete);
         }
         function OnItemsComplete(result) {
             for (var i = 0; i < result.length; i++) {
 
                 var item = new Telerik.Web.UI.RadComboBoxItem();
                 item.set_text(result[i].Items + "");
 
                 var grid = $find("ctl00_BodyContentPlaceHolder_grdInvoiceItems");
                 var masterTbl = grid.get_masterTableView();
                 var gridRow = masterTbl.get_dataItems()[0];
 
                 var comboBox = gridRow.findControl("ddlItems");
           
                 comboBox.get_items().add(item);
             }
         }
Thanks,
ron.

3 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 19 Feb 2013, 07:46 AM
Hi Ron,

How do you populate your combo - using WebServiceSettings:
<WebServiceSettings Path="InvoiceWebService.asmx" Method="GetItems" /
or using jQuery?

You may try to call requestItems() after adding the new item. This should populate your combo with the new data:
function addNewItem() {
    //add item to the Database via Web Service
 
    var rcb = $find('RadComboBox1');
    //Clear all items
    rcb.clearItems();
    //Request all items again
    rcb.requestItems();
}

Greetings,
Hristo Valyavicharski
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
Ron
Top achievements
Rank 1
answered on 19 Feb 2013, 12:02 PM
Hristo,   

I was able to resolve this issue but thanks anyway. I am struggle with another issue along the same lines maybe you can help. So, my combo box is populate within the first column of the grid. When clicked the drop down menu is displayed with a list of items. Right now the list of items is only showing for the first row because it's hard coded.  I can't use events such as the onmouseover to get the row index and pass it in because I'm using the OnGridCreated event to populate the combobox. With that logic I don't know how to dynamically get the row ID so that I can populate the combo box for that particular row. I tried the OnColumnClick but no success.
Please see image for a visual example. In the example you can see when the first row is click the combo is populate, but the second row or any other doesn't populate. Any help will be greatly appreciated.

Thanks,
Ron.
function GridCreated(sender, eventArgs) {
            InvoiceWebService.GetItemsByCompanyId(sessionStorage.CompanyId, OnItemsComplete);
        }
        function OnItemsComplete(result) {
 
            for (var i = 0; i < result.length; i++) {
 
                var item = new Telerik.Web.UI.RadComboBoxItem();
                item.set_text(result[i].Items + "");
 
                var grid = $find("<%=grdInvoiceItems.ClientID%>");
                var masterTbl = grid.get_masterTableView();
                var gridRow = masterTbl.get_dataItems()[0]; //hard coded to first row
 
                var comboBox = gridRow.findControl("ddlItems");
                comboBox.get_items().add(item);
            }
        }


0
Hristo Valyavicharski
Telerik team
answered on 20 Feb 2013, 06:39 AM
Hi Ron,

You can try to populate the combo in OnClientDropDownOpening event and keep the combo in global variable:

<script type="text/javascript">
    //Put your JavaScript code here.
    var combo;
 
    function addNewItem() {
        //add item to the Database via Web Service
 
        //Clear all items
        combo.clearItems();
        //Request all items again
        combo.requestItems();
    }
 
    function OnClientDropDownOpening(sender, args) {
        combo = sender;
 
        //Clear all items
        sender.clearItems();
        //Request all items again
        sender.requestItems();
    }
</script>

I'm attaching small sample showing how to implement such functionality. 

Regards,
Hristo Valyavicharski
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
Ron
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Ron
Top achievements
Rank 1
Share this question
or