load combobox items on first use?

2 posts, 0 answers
  1. troyboy
    troyboy avatar
    9 posts
    Member since:
    Mar 2007

    Posted 14 Nov 2010 Link to this post

    Hi, I am using load on demand because my database is slow and i don't want to preload all my combo boxes when the page first initializes.

    The load on demand for the radcombobox almost works except:
    1) I can't turn off text typing
    2) The loaded options don't cache. Each time I refresh the radcombobox, the loaded combobox items are gone and when i focus on the combobox the 'loading...' happens again.

    So basically I just want a regular combobox with some items that only load on the first use of the combobox and then are cached for the lifetime of the page. Is it possible?

    Here is a code snippet:

    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="Button1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadComboBox1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
      
    <telerik:RadComboBox ID="RadComboBox1" Runat="server" 
        ChangeTextOnKeyBoardNavigation="False" EmptyMessage="Select A Company..." 
        EnableItemCaching="True" EnableLoadOnDemand="True" EnableTextSelection="False" 
        onitemsrequested="RadComboBox1_ItemsRequested" >
    </telerik:RadComboBox>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 Nov 2010 Link to this post

    Hello ,
    You can try the following javascript code to cancel the text typing.

    Javascript:
    function OnClientLoad(sender, eventArgs)
      {
           sender.get_inputDomElement().disabled = true;
           sender.get_inputDomElement().style.color = "black";
       }

    You can make use of the session variables,in order to avoid the querying from DB on each postback . Here is the sample code.

    C#:
    protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
      {
          if (Session["data"] != null)
          {
              DataTable dt1 = (DataTable)Session["data"];
              foreach (DataRow row in dt1.Rows)
              {
                  RadComboBoxItem item = new RadComboBoxItem(row["FirstName"].ToString());
                  RadComboBox1.Items.Add(item);
              }
              return;
          }
          RadComboBox combo = (RadComboBox)o;      
          combo.Items.Clear();
          SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString2"].ConnectionString);
          SqlCommand cmd = new SqlCommand("select EmployeeID,FirstName from Employees", con);
          SqlDataAdapter da = new SqlDataAdapter(cmd);
          DataTable dt = new DataTable();
          Session["data"] = dt;
          da.Fill(dt);
          con.Close();
          foreach (DataRow row in dt.Rows)
          {
              RadComboBoxItem item = new RadComboBoxItem(row["FirstName"].ToString());
              combo.Items.Add(item);
          }
        
      }

    Thanks,
    Princy.
Back to Top