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

Combobox and cached objectdatasource

4 Answers 214 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 23 May 2010, 09:46 AM
Hallo,

I´m using a radcombobox together with an objectdatasource. The combobox is placed within the edititemtemplate of a formview. The objectdatasource has "enablecaching", the combobox "EnableItemCaching" set to true.

 

<asp:ObjectDataSource ID="ODS_Country" runat="server" EnableCaching="True" 
    
SelectMethod="GetData"

 

 

    TypeName="Telerik.DataSet1TableAdapters.REF_CountryTableAdapter">

 

 

</asp:ObjectDataSource>

 


 

<telerik:RadComboBox ID="rcb_Country" Runat="server" 
    
DataSourceID="ODS_Country"
    
DataTextField="Country" DataValueField="OID" 
    
EnableItemCaching="True" >

 

 

</telerik:RadComboBox>

 


But everytime I switch formview to editmode there is access to my database. How can I achieve, that the item data of the combobox are only read once from my db using caching mechanism of objectdatasource.

Thank´s for your help.
Robert

4 Answers, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 27 May 2010, 12:15 PM
Hello Robert Meyer,

The controls placed in EditTemplate(or any other template) of the FormView are recreated and repopulated with data again every time the control enters "Edit" mode.
That is why cashing items within the RadComboBox in this scenario is not supported.

However your idea of cashing the ObjectDataSource is a good approach to achieve similar results.

All the best,
Kalina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Robert
Top achievements
Rank 1
answered on 27 May 2010, 01:18 PM
Hello Kalina,

thank you for your response.

I found a way to eliminate the roundtrip to the db by enabling LoadOnDemand and leaving the DatasourceID of the combobox empty. Instead I set the DatasourceID in the ItemsRequestMethod.

 

 

 

<telerik:RadComboBox ID="rcb_Country" Runat="server" EnableItemCaching="True" EnableLoadOnDemand="True" OnItemsRequested="rcbCountry_ItemsRequested" > 
 

 

 

Protected Sub rcbCountry_ItemsRequested(ByVal o As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)   
    o.DataSourceID = "ODS_Country" 
    o.DataValueField = "OID" 
    o.DataTextField = "Country" 
    o.DataBind()  
End Sub  
 
 

The advantage is, that the same (cached Datasource) can be used for multiple comboboxes that use the same data. Furthermore there is no roundtrip to the db, when formview mode is changed.

But now I have another question.
After the first call to the ItemsRequested method I have all data loaded so it´s not necessary to call the method again. Is it possible to eliminate the repeated call. I tried
o.EnableLoadOnDemand=False at the end of the ItemsRequested Method but this does not work.

Any ideas ?
Robert 

 

 

0
Accepted
Kalina
Telerik team
answered on 31 May 2010, 04:59 PM
Hello Robert Meyer,

Let me explain to you how Load-On-Demand works – when control is loaded - it has no items. Items are requested when the user types in the input area or clicks on the drop-down toggle image.

So if the RadComboBox dropdown is already populated with data - there will be no new request for items unless user types at RadComboBox input. 

However you can have control over requests following these steps:
1.   Remove the EnableLoadOnDemand property
<%--EnableLoadOnDemand="true"--%>
<telerik:RadComboBox ID="RadComboBox1" runat="server"
    EmptyMessage=" - select - "
    OnClientDropDownOpening="OnClientDropDownOpeningHandler"
    OnItemsRequested="RadComboBox1_ItemsRequested"
    MarkFirstMatch="true" >
</telerik:RadComboBox>

2.   Handle  OnClientDropdownOpening event and check if there are items loaded at RadComboBox dropdown - if there are no items – you can call client-side  requestItems() function and perform request, otherwise no request will be performed.
function OnClientDropDownOpeningHandler(sender, eventArgs)
{
 
    var items =  sender.get_items();
    if(items.get_count()== 0 )
    {
        sender.requestItems("", false);
    }
}

More details about requestItems() method you can find here.

Regards,
Kalina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Robert
Top achievements
Rank 1
answered on 05 Jun 2010, 01:08 PM
Hello Kalina,

thank´s a lot for your help. Problem is solved now.

Robert
Tags
ComboBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Robert
Top achievements
Rank 1
Share this question
or