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

load combobox items on first use?

1 Answer 94 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
troyboy
Top achievements
Rank 1
troyboy asked on 14 Nov 2010, 08:10 AM
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>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Nov 2010, 01:05 PM
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.
Tags
ComboBox
Asked by
troyboy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or