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

Rebind Databound RadComboBox on RadWindow Close

1 Answer 254 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Megan
Top achievements
Rank 1
Megan asked on 04 Apr 2013, 07:22 PM

I have a RadComboBox that displays a list of appropriate addresses to ship to from the user's address book.  When choosing which address to ship to they select from this dropdown.  However, they want the ability to edit their address book without having to leave the Order Form.  I solved this with an additional button that opens in a RadWindow the same page they use to edit their address book from their profile.  They can add, change, search for addresses easily from this window.  When they close the window however the changes are not reflected in the RadComboBox.

I am using Ajax on the page already and it is a form so if I allow the page to postback it can sometimes lose some of the information that was in the form if the user changed it.

Is there a way that I can rebind the RadComboBox to fetch the latest information similar to how the RadGrid can rebind?

Javascript:
<script type="text/javascript">
    function ShowAddressBook(button, args) {
        if (!confirm('This action will redirect you to your Address Book.  You will lose all unsaved information. Are you sure?')) {
            return false;
        }
        else {
            $find("<%=AddressBookWindow.ClientID %>").show();
        }
    }
    function RefreshAddresses() {
        location.reload();
    }
</script>

ASPX
<telerik:RadComboBox runat="server" ID="rcbAddress" Width="200px" EnableItemCaching="false" EnableLoadOnDemand="true"
                            DataSourceID="dsAddressBook" DropDownWidth="250px" HighlightTemplatedItems="true"
                            EmptyMessage="Select Address" DataTextField="AddressName" DataValueField="AddressID">
                            <ItemTemplate>
                                <div class="boxitem">
                                    <div class="addressLabel"><%# DataBinder.Eval(Container.DataItem, "AddressName") %></div>
                                    <div class="boxdetail">
                                    <div class='<%# DataBinder.Eval(Container.DataItem, "AddressTypeClass") %>'> </div>
                                    <div class="addressFormat">
                                        <strong><%# DataBinder.Eval(Container.DataItem, "RecipiantName") %></strong><br />
                                        <%# DataBinder.Eval(Container.DataItem, "Address1") %><br />
                                        <%# DataBinder.Eval(Container.DataItem, "Address2") %><br />
                                        <%# DataBinder.Eval(Container.DataItem, "City") %>, <%# DataBinder.Eval(Container.DataItem, "State") %> <%# DataBinder.Eval(Container.DataItem, "ZIP") %>
                                        <%# DataBinder.Eval(Container.DataItem, "Country") %>
                                    </div>
                                    </div>
                                </div>
                            </ItemTemplate>
                        </telerik:RadComboBox>
 
<telerik:RadButton ID="btnShowAddressBook" CausesValidation="false" AutoPostBack="false" runat="server" OnClientClicked="ShowAddressBook" Text="Edit Address Book">
<Icon PrimaryIconCssClass="rbOpen" PrimaryIconLeft="4" PrimaryIconTop="4" />
</telerik:RadButton>
 
---
 
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    <Windows>
        <telerik:RadWindow ID="AddressBookWindow" Modal="true" VisibleStatusbar="false" OnClientClose="RefreshAddresses" Title="Manage Address Book" NavigateUrl="/SiteControls/AddressBook.aspx" runat="server" AutoSize="true" style="z-index:8000;" />
    </Windows>
</telerik:RadWindowManager>

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 09 Apr 2013, 03:46 PM
Hi Megan,

Try to handle OnItemsRequested server event of the combo and rebind the combo with the new data:
protected void rcbAddress_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    dsAddressBook.DataBind();
 
    RadComboBox rcb = (RadComboBox)sender;
    rcb.DataBind();
}

To fire OnItemsRequested  you will have to call requestItems() method  in RefreshAddresses function:
function RefreshAddresses() {
    var combo = $find('rcbAddress');
    combo.requestItems();
    //location.reload();
}


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