Hi,
my client wants to see a combobox where he could write patterns of items while list of all items containing the pattern is decreased.
At the same time he wants that the items will be shown with check boxes so at the end of operation he could check several of them.
I have learned all examples that you show in your demo projects but did not find exactly what I want. Particularly I tried to use CheckBoxes property but then I found in http://www.telerik.com/help/aspnet-ajax/combobox-usability-checkboxes.html that
"Load On Demand functionality is not supported". Really when I tried this option with empty list of RadComboBoxItems the application stopped to react.
Also I tried to use template based on ideas from http://www.telerik.com/community/forums/aspnet-ajax/combobox/add-item-template-to-radcombobox-dynamically.aspx
But I use handler of ItemsRequested event. I succeeded to show a combo with check boxes whose number of items is decreased when an user inserts some text. But when I let to combo to be closed and then tried to open it I get an error: The state information is invalid for this page and might be corrupted.
I add some code then I use.
So the question: is it possible to realize the above task?
Thank you
Evgeny
my client wants to see a combobox where he could write patterns of items while list of all items containing the pattern is decreased.
At the same time he wants that the items will be shown with check boxes so at the end of operation he could check several of them.
I have learned all examples that you show in your demo projects but did not find exactly what I want. Particularly I tried to use CheckBoxes property but then I found in http://www.telerik.com/help/aspnet-ajax/combobox-usability-checkboxes.html that
"Load On Demand functionality is not supported". Really when I tried this option with empty list of RadComboBoxItems the application stopped to react.
Also I tried to use template based on ideas from http://www.telerik.com/community/forums/aspnet-ajax/combobox/add-item-template-to-radcombobox-dynamically.aspx
But I use handler of ItemsRequested event. I succeeded to show a combo with check boxes whose number of items is decreased when an user inserts some text. But when I let to combo to be closed and then tried to open it I get an error: The state information is invalid for this page and might be corrupted.
I add some code then I use.
So the question: is it possible to realize the above task?
Thank you
Evgeny
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
public partial class TestPages_TestComboCheckBoxes : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
//this is name of combo
rcbMitkanKav.ItemTemplate = new ItemTemplate();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
LoadData();
}
protected void rcbMitkanKav_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
DataTable dtMitkanimKavim = new DataTable();
const string MethodName = "SearchPopWindow.rcbMitkanKav_ItemsRequested";
int UserErrorCode = 6;
try
{
string sComboText = e.Text;
//pattern to search
string sSearchLetter = "";
if (sComboText == "")
{
sSearchLetter = "";
}
if (sComboText != "")
{
sSearchLetter = sComboText;
}
try
{
if (sSearchLetter.Length <
3
)
return;
int
queryId
=
1
;
dtMitkanimKavim
=
GetSearchResultByWord
(sSearchLetter, queryId);
int
itemsPerRequest
=
30
;
int
itemOffset
= e.NumberOfItems;
int
endOffset
=
itemOffset
+ itemsPerRequest;
if (endOffset > dtMitkanimKavim.Rows.Count)
{
endOffset = dtMitkanimKavim.Rows.Count;
}
if (endOffset == dtMitkanimKavim.Rows.Count)
{
e.EndOfItems = true;
}
else
{
e.EndOfItems = false;
}
rcbMitkanKav.DataSource = dtMitkanimKavim;
rcbMitkanKav.DataBind();
}
catch
{
e.Message = "אין רשומות";
}
}
catch (Exception ex)
{
throw ex;
}
}
private void LoadData()
{
try
{
///here code to load data from database int a table and save it in Session
}
catch (Exception ex)
{
throw ex;
}
}
/// <
summary
>
///
/// </
summary
>
/// <
param
name
=
"sSearchWord"
>curren input</
param
>
/// <
param
name
=
"queryId"
></
param
>
/// <
returns
></
returns
>
public DataTable GetSearchResultByWord(string sSearchWord, int queryId)
{
DataTable dt = new DataTable();
//build new datable is contain two columns
dt.Columns.Add("ComboValue");
dt.Columns.Add("ComboText");
DataRow newRow = null;
string currentValue = string.Empty;
///array of rows from a table according to current input sSearchWord
DataRow[] drSelected = null;
///replace "'" to sql select
if (sSearchWord.Contains("'"))
sSearchWord = sSearchWord.Replace("'", "''");
try
{
drSelected = SessionManager.dtMitkanimKavim.Select("NameReferenceId LIKE '" + "%" + sSearchWord + "%" + "'") as DataRow[];
//add array to new datable
foreach (DataRow row in drSelected)
{
dt.Rows.Add(row);
}
}
catch (Exception ex)
{
throw ex;
}
return dt;
}
}
class ItemTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
CheckBox chk = new CheckBox();
//chk.ID = "chk1";
chk.Attributes.Add("onclick", "SetCheckedStateToServer()");
Label lbl = new Label();
Table table = new Table();
TableRow mainRow = new TableRow();
TableCell cell1 = new TableCell();
cell1.Controls.Add(chk);
cell1.DataBinding += new EventHandler(cell1_DataBinding);
mainRow.Cells.Add(cell1);
TableCell cell2 = new TableCell();
cell2.Controls.Add(lbl);
cell2.DataBinding += new EventHandler(cell2_DataBinding);
mainRow.Cells.Add(cell2);
table.Rows.Add(mainRow);
container.Controls.Add(table);
}
private void cell1_DataBinding(object sender, EventArgs e)
{
TableCell target = (TableCell)sender;
(target.Controls[0] as CheckBox).Checked = true;
}
private void cell2_DataBinding(object sender, EventArgs e)
{
TableCell target = (TableCell)sender;
RadComboBoxItem item = (RadComboBoxItem)target.BindingContainer;
(target.Controls[0] as Label).Text =
((DataRowView)(item.DataItem)).Row[1].ToString();
}
}