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

Prevent loading all items inside combo

7 Answers 102 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mick
Top achievements
Rank 1
Mick asked on 30 Dec 2008, 11:22 AM
hi

I would not like to show all items inside the combo when the page load >>>> I just want to load data when user type something
just like yahoo search combo box.

can u help please.
regards

7 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 30 Dec 2008, 11:39 AM
Hi Mick,

I suggest you use Load-On-Demand mechanism of RadComboBox.

Greetings,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mick
Top achievements
Rank 1
answered on 30 Dec 2008, 12:11 PM
Can you give example please because the link you gave it me does not do what I am looking for
0
Yana
Telerik team
answered on 30 Dec 2008, 03:30 PM
Hello Mick,

Could you please explain in more details your requirements?

Best wishes,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mick
Top achievements
Rank 1
answered on 30 Dec 2008, 09:27 PM

hi Yana

look i will explain in more details what i am looking for:

in my combo box list I got about 1000 records when page load and when user edit in comob it start filter the list >>>> this is what happen .... but i want to do is:

when page load the combo box should be empty just show message "please begin typing..." and when user type i start reterving data as filtered so I avoid showing 1000 records inside comobo

please take a look at yahoo search box to know more what i am looking for.
by the way i am using the following version of radcontrols : RadControls_Q2_2006_SP2

 

Thanks for help

0
Princy
Top achievements
Rank 2
answered on 02 Jan 2009, 09:43 AM
Hi Mick,

One suggestion is that you can use "TextChanged" EventHandler instead of "ItemsRequested" for adding RadComboBoxItems. Then you can populate the RadComboBox from code behind. Try the following code snippets.

CS:
protected void RadComboBox1_TextChanged(object sender, EventArgs e) 
    RadComboBox1.Items.Clear(); 
    string sql = "SELECT * from Customers WHERE CompanyName LIKE '" + RadComboBox1.Text + "%'"
    SqlDataAdapter adapter = new SqlDataAdapter(sql,ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString); 
    DataTable data = new DataTable(); 
    adapter.Fill(data); 
    for (int i = 0; i < data.Rows.Count; i++) 
    { 
        RadComboBox1.Items.Add(new RadComboBoxItem(data.Rows[i]["CompanyName"].ToString(), data.Rows[i]["CompanyName"].ToString())); 
    } 


Another feature that can be used when lots of items are to be added is the adding items via callback upon scrolling the drop down. To enable this feature, the EnableVirtualScrolling property should be enabled. Thus, items will be dynamically added when scrolling down the drop-down area.

Thanks,
Princy.
0
Mick
Top achievements
Rank 1
answered on 09 Jan 2009, 08:01 PM

Thanks for your help!! but i tried your code but does not work here is my code:

I just want when user open dropdown list it should be empty till user write something on dropdownlist

 

 

private void InitializeComponent()

 

{

 

this.RadComboBox1.ItemsRequested += new Telerik.WebControls.RadComboBoxItemsRequestedEventHandler(this.RadComboBox1_TextChanged);

 

 

this.Load += new System.EventHandler(this.Page_Load);

 

}

 

protected void RadComboBox1_TextChanged(object o, RadComboBoxItemsRequestedEventArgs e)

 

{

 

string text = e.Text;

 

 

string sql = "SELECT Stud_ID,StudName from Students WHERE StudName LIKE '" + text.Replace("'", "''") + "%'";

 

 

RadComboBox combo = (RadComboBox)o;

 

combo.Items.Clear();

 

SqlDataAdapter sSQLAdp = new SqlDataAdapter(sql, ObjConn);

 

 

DataTable data = new DataTable();

 

sSQLAdp.Fill(data);

 

try

 

 

 

 

{

 

int itemsPerRequest = 5;

 

 

int itemOffset = e.NumberOfItems;

 

 

int endOffset = itemOffset + itemsPerRequest;

 

 

if (endOffset > data.Rows.Count)

 

{

endOffset = data.Rows.Count;

}

 

if (endOffset == data.Rows.Count)

 

{

 

 

// e.EndOfItems = true;

 

 

 

 

}

 

else

 

 

 

 

{

 

//e.EndOfItems = false;

 

 

 

 

}

 

for (int i = itemOffset; i < endOffset; i++)

 

{

RadComboBox1.Items.Add(

new RadComboBoxItem(data.Rows[i]["StudName"].ToString(), data.Rows[i]["StudName"].ToString()));

 

}

 

if (data.Rows.Count > 0)

 

{

e.Message =

String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString());

 

}

 

else

 

 

 

 

{

e.Message =

"No matches";

 

}

}

 

catch

 

 

 

 

{

e.Message =

"No matches";

 

}
}

0
Chris
Top achievements
Rank 1
answered on 29 Jan 2009, 09:37 PM
I don't know if you're doing this or not, but silly me, I was pre-loading the control and then wondering why it was taking so long to load.  I think that you can also add code, like !controlname.IsCallBack, to the pageload method to ensure a quick response.  I hope that this helps.  Thanks.

Chris
Tags
ComboBox
Asked by
Mick
Top achievements
Rank 1
Answers by
Yana
Telerik team
Mick
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Share this question
or