I have created a function to combine all ComboBox SQL statement into it, it is work for showing the data value, but I found that when I click the footer message, it will show up duplicated records in the ComboBox value. Did I miss something? Is it the proper way to do it? Thanks in advance.
My questions are:
1. How to prevent duplicated value? I did try to use EnableAutomaticLoadOnDemand="true", but I have got another error : "There is no assigned datasource. unable to complete callback request".
2. How can I set the paging into the ComboBox like the Demo "Items 1 of 20 out of 90", seems I cannot pass the NumberOfItems parameter into it.
My Code as below:
cbTestA.BindCombobox();
cbTestB.BindCombobox();
cbTestC.BindCombobox();
public void BindCombobox()
{
try
{
//Default parameters
AllowCustomText = true;
Filter = RadComboBoxFilter.Contains;
MarkFirstMatch = true;
EnableAutomaticLoadOnDemand = false;
ShowMoreResultsBox = true;
EnableVirtualScrolling = true;
ItemsPerRequest = 20;
string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["Context"].ConnectionString;
SqlConnection cs = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
cs.Open();
switch (this.ID)
{
case "cbTestA":
{
cmd.CommandText = "select id as dtxt,id as dval from COMPANY";
}
break;
case "cbTestB":
{
cmd.CommandText = "select id as dtxt,id as dval from COUNTRY";
}
break;
case "cbTestC":
{
cmd.CommandText = "select id as dtxt,id as dval from USERNAME";
}
break;
}
cmd.Connection = cs;
DataSet dset = new DataSet();
SqlDataAdapter dp = new SqlDataAdapter(cmd);
dp.Fill(dset);
DataSource = dset;
DataTextField = "dtxt";
DataValueField = "dval";
DataBind();
//int itemOffset = this.NumberOfItems;
//int endOffset = Math.Min(itemOffset + ItemsPerRequest, 20); //dset.Rows.Count);
//this.EndOfItems = endOffset == 20; // data.Rows.Count;
//this.Message = GetStatusMessage(endOffset, 20); //data.Rows.Count);
}
catch (Exception)
{
//MessageBox.Show(ex.Message);
}
}