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

[Solved] Disable LoadOnDemand based on size of recordset

4 Answers 110 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 22 Jan 2010, 03:04 PM

Is there aneasy way to turn off LoadOndemand feature?


We have auser control which build on radComboBox with default LoadOnDemand value to true,and we like to disable the LoadOnDemand if recordset has less than 3000records. So thecombobox will look like regular list box.

4 Answers, 1 is accepted

Sort by
0
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 23 Jan 2010, 05:45 PM
What about doing a Count in the code behind Page_Load (or just grab the data)...if count < 3000 then assign the dataset to the DataSource value and set load on demand = false
0
David
Top achievements
Rank 1
answered on 23 Jan 2010, 08:10 PM
thanks, tried and it didn't work.
0
Accepted
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 25 Jan 2010, 01:31 PM
Sorry, Page_Init :)

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
    </telerik:RadScriptManager> 
    <telerik:RadComboBox ID="combo" runat="server" EnableLoadOnDemand="true"  
        DataTextField="submissionid" DataValueField="submissionid" EnableVirtualScrolling="true"  
                        DropDownWidth="300" Width="300" Height="300"  
                        onitemsrequested="combo_ItemsRequested" /> 
     
    </form> 
</body> 
</html>  
 


using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
using System.Data; 
using System.Web.Security; 
using System.Configuration; 
using DataSet1TableAdapters; 
using Telerik.Web.UI; 
 
public partial class _Default : System.Web.UI.Page  
    private const int ItemsPerRequest = 10; 
 
 
    protected void Page_Init(object sender, EventArgs e) { 
        //If the rows returned are less than 3000 
        if (GetData().Rows.Count < 3000) { 
            //Disable the LoadOnDemand Stuff 
            combo.EnableVirtualScrolling = false
            combo.ItemsRequested -= new RadComboBoxItemsRequestedEventHandler(combo_ItemsRequested); 
            combo.EnableLoadOnDemand = false
 
            //Bind the combo to the data 
            combo.DataSource = _data; 
            combo.DataBind(); 
        } 
    } 
 
    /// <summary> 
    /// Load on Demand Event 
    /// </summary> 
    protected void combo_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { 
        ss_submissionResponseTableAdapter tableAdapter = new ss_submissionResponseTableAdapter(); 
        DataSet1.ss_submissionResponseDataTable dataTable = this.GetData(); 
 
        int itemOffset = e.NumberOfItems; 
        int endOffset = Math.Min(itemOffset + ItemsPerRequest, dataTable.Rows.Count); 
        e.EndOfItems = endOffset == dataTable.Rows.Count; 
 
        for (int i = itemOffset; i < endOffset; i++) { 
            DataSet1.ss_submissionResponseRow row = dataTable.Rows[i] as DataSet1.ss_submissionResponseRow; 
            combo.Items.Add(new RadComboBoxItem(row.submissionid.ToString(), row.submissionid.ToString())); 
        } 
 
        e.Message = GetStatusMessage(endOffset, dataTable.Rows.Count); 
    } 
 
    /// <summary> 
    /// Get the Data, probably pass in a text value like the Demo  
    /// </summary> 
    private DataSet1.ss_submissionResponseDataTable _data = null
    private DataSet1.ss_submissionResponseDataTable GetData() { 
        if (_data == null) { 
            ss_submissionResponseTableAdapter tableAdapter = new ss_submissionResponseTableAdapter(); 
            DataSet1.ss_submissionResponseDataTable dataTable = null
 
            try { 
                _data = tableAdapter.GetData(); 
            } catch (Exception ex) { 
 
            } finally { 
                tableAdapter.Dispose(); 
            } 
        } 
        return _data; 
    } 
 
    /// <summary> 
    /// Status Event 
    /// </summary> 
    private static string GetStatusMessage(int offset, int total) { 
        if (total <= 0) 
            return "No matches"
 
        return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total); 
    } 
 

0
David
Top achievements
Rank 1
answered on 25 Jan 2010, 06:33 PM
Thanks It works well!
Tags
ComboBox
Asked by
David
Top achievements
Rank 1
Answers by
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
David
Top achievements
Rank 1
Share this question
or