I have a large number of combobox items inside a grid. The combobox display those
items to slow, so I tried to load Items on portions and after short search a found
what I was looking for. I found the example demo ComboBox - Load on Demand Modes . But I can’t figure it out how to do the same
thing inside a Grid?
4 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 07 Apr 2014, 08:42 AM
Hi Joseph,
Please have a look into the sample code snippet which works fine at my end.
ASPX:
C#:
Thanks,
Shinu.
Please have a look into the sample code snippet which works fine at my end.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
AutoGenerateColumns
=
"false"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
UniqueName
=
"OrderID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
telerik:RadComboBox
ID
=
"RadComboBox2"
runat
=
"server"
Width
=
"250"
Height
=
"150"
EmptyMessage
=
"Select a Company"
EnableLoadOnDemand
=
"True"
ShowMoreResultsBox
=
"true"
EnableVirtualScrolling
=
"true"
OnItemsRequested
=
"RadComboBox2_ItemsRequested"
>
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
private
const
int
ItemsPerRequest = 10;
protected
void
RadComboBox2_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
RadComboBox combo = (RadComboBox)sender;
DataTable data = GetData(e.Text);
int
itemOffset = e.NumberOfItems;
int
endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
e.EndOfItems = endOffset == data.Rows.Count;
for
(
int
i = itemOffset; i < endOffset; i++)
{
combo.Items.Add(
new
RadComboBoxItem(data.Rows[i][
"CompanyName"
].ToString(), data.Rows[i][
"CompanyName"
].ToString()));
}
}
private
static
DataTable GetData(
string
text)
{
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT * from Customers WHERE CompanyName LIKE @text + '%'"
,ConfigurationManager.ConnectionStrings[
"ConnectionString"
].ConnectionString);
adapter.SelectCommand.Parameters.AddWithValue(
"@text"
, text);
DataTable data =
new
DataTable();
adapter.Fill(data);
return
data;
}
Thanks,
Shinu.
0

Joseph
Top achievements
Rank 1
answered on 07 Apr 2014, 04:56 PM
Hi Shinu
Thank you for your quick answer. The example works fine, but still when I scroll down, the combox triggers the OnItemsRequested even when all items are loaded.
So the next question is how to stop from OnItemsRequested from firing when all items are loaded?
Thank you for your quick answer. The example works fine, but still when I scroll down, the combox triggers the OnItemsRequested even when all items are loaded.
So the next question is how to stop from OnItemsRequested from firing when all items are loaded?
0
Accepted

Shinu
Top achievements
Rank 2
answered on 08 Apr 2014, 04:17 AM
Hi Joseph,
In this scenario the RadComboBox is not loading all the items initially. It will load only first 10 items initially because here the ItemsPerRequest is set it as 10. So when you are scrolling it will load next 10 items. This is the way of working ItemsRequestedevent. As a suggestion you can do the following modification in your ItemsRequested event to achieve your scenario.
C#:
Thanks,
Shinu.
In this scenario the RadComboBox is not loading all the items initially. It will load only first 10 items initially because here the ItemsPerRequest is set it as 10. So when you are scrolling it will load next 10 items. This is the way of working ItemsRequestedevent. As a suggestion you can do the following modification in your ItemsRequested event to achieve your scenario.
C#:
protected
void
RadComboBox2_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
RadComboBox combo = (RadComboBox)sender;
DataTable data = GetData(e.Text);
for
(
int
i = 0; i < data.Rows.Count; i++)
{
combo.Items.Add(
new
RadComboBoxItem(data.Rows[i][
"CompanyName"
].ToString(), data.Rows[i][
"CompanyName"
].ToString()));
}
}
Thanks,
Shinu.
0

Joseph
Top achievements
Rank 1
answered on 09 Apr 2014, 05:36 AM
Thanks Shinu. It is working fine :)