I have to create RadComboBoxes dynamically in a Repeater. I'm trying to find a way to set the WebServiceSettings in the code behind. I found this code that uses JQuery:
function clientLoad(sender) {
sender.set_webServiceSettings('{"path":"Products.asmx","method":"GetCompanyNames"}');
}
But the service does not return Json so I receive an error. I create the control in the code behind like this:
List <ModuleView.JobBO> list = new List<ModuleView.JobBO>();
switch (moduledatakey)
{
case "JOB":
list = JobDA.Job_GetList_ByJobNumberContains(DB_Context, mfilter, top, companyId);
RadComboBox ddl = new RadComboBox();
ddl.ID = "ddlJob";
ddl.ItemDataBound += new RadComboBoxItemEventHandler(ddlJob_ItemDataBound);
ddl.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(ddlJob_ItemsRequested);
ddl.EmptyMessage = "Type to Select...";
ddl.EnableLoadOnDemand = true;
ddl.EnableTextSelection = true;
ddl.DataSource = list;
ddl.Text = "";
ddl.DataValueField = "JobId";
ddl.DataBind();
ddl.OnClientLoad = "clientLoad";
ddl.DropDownAutoWidth = Telerik.Web.UI.RadComboBoxDropDownAutoWidth.Enabled;
ddl.AutoPostBack = true;
ddl.EnableViewState = false;
ddl.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(qfTicket_cmbJob_SelectedIndexChanged);
plc2.Controls.Add(ddl);
break;
}
and use the following to implement the "LoadOnDemand":
protected void ddlJob_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
string mfilter = e.Text;
int top = 50;
Guid? companyId = null;
List<ModuleView.JobBO> list = new List<ModuleView.JobBO>();
list = JobDA.Job_GetList_ByJobNumberContains(DB_Context, mfilter, top, companyId);
((RadComboBox)sender).DataSource = list;
((RadComboBox)sender).DataBind();
}
This works fine accept the LoadOnDemand is EXTREMELY slow. I want to use the following web method which we are using on other comboboxes that are NOT created dynamically.
[WebMethod(EnableSession = true)]
public RadComboBoxData GetJobs(RadComboBoxContext context)
{
//get data
List<ModuleView.JobBO> lComps = new List<ModuleView.JobBO>();
COG_ContextDB db_context = UtilityBA.GetAspNetDataContext();
//company id?
App_Code_COGS.UI.UIUtilities.GridState oState = App_Code_COGS.UI.UIUtilities.GetGridStateFromSession();
Guid? gCustomerId = (UtilityBA.IsValidGuid(oState.CustomerId) ? (Guid?)Guid.Parse(oState.CustomerId) : null);
//get data
lComps = JobBA.Job_GetList_ByJobNumberContains(db_context, context.Text, 50, gCustomerId);
if (lComps == null)
{
lComps = new List<ModuleView.JobBO>();
}
//prep data controls
RadComboBoxData comboData = new RadComboBoxData();
List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems);
//get top N
try
{
int itemsPerRequest = 10;
int itemOffset = context.NumberOfItems;
int endOffset = itemOffset + itemsPerRequest;
if (endOffset > lComps.Count)
{
endOffset = lComps.Count;
}
if (endOffset == lComps.Count)
{
comboData.EndOfItems = true;
}
else
{
comboData.EndOfItems = false;
}
result = new List<RadComboBoxItemData>(endOffset - itemOffset);
for (int i = itemOffset; i < endOffset; i++)
{
RadComboBoxItemData itemData = new RadComboBoxItemData();
itemData.Text = ((ModuleView.JobBO)lComps[i]).JobNumber.ToString() + " - " + ((ModuleView.JobBO)lComps[i]).JobName.ToString();
itemData.Value = ((ModuleView.JobBO)lComps[i]).JobId.ToString();
result.Add(itemData);
}
if (lComps.Count > 0)
{
comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), lComps.Count.ToString());
}
else
{
comboData.Message = "No matches";
}
}
catch (Exception e)
{
comboData.Message = e.Message;
}
var json = JsonConvert.SerializeObject(result);
comboData.Items = result.ToArray();
return comboData;
}
Is there any way to assign the WebServiceSettings in the codebehind?