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

Combo box related issue

1 Answer 59 Views
Sample Applications
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kishore
Top achievements
Rank 1
Kishore asked on 17 May 2014, 06:08 AM
Hi,
      I am using telerik combo box in my application. I fill combo box using service. I want to restrict user to enter any characters in combo box after selecting from dropdown. please suggest me is there any properties to disable.

here is my code:
​ <telerik:RadComboBox ID="comsystemstatus" runat="server" EmptyMessage="Select" EnableLoadOnDemand="true"
ShowMoreResultsBox="true" AllowCustomText="false"
EnableVirtualScrolling="true">
<WebServiceSettings Method="GetFaci_SystemStatus" Path="CaseService.asmx" />
</telerik:RadComboBox>

and my service:


[WebMethod]
public RadComboBoxData GetFaci_SystemStatus(RadComboBoxContext context)
{
EDSMESS_User_Information EDSMESS_User = new EDSMESS_User_Information();
string query = "";
query += "SELECT distinct Faci_SystemStatus FROM FACI where Faci_SystemStatus LIKE '" + context.Text + "' + '%' and Faci_SystemStatus Is Not Null ";
DataSet ds = new DataSet();
ds = EDSMESS_User.GetEDSMESSData(query);
List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems);
RadComboBoxData comboData = new RadComboBoxData();
try
{
int itemsPerRequest = 10;
int itemOffset = context.NumberOfItems;
int endOffset = itemOffset + itemsPerRequest;
if (endOffset > ds.Tables[0].Rows.Count)
{
endOffset = ds.Tables[0].Rows.Count;
}
if (endOffset == ds.Tables[0].Rows.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 = ds.Tables[0].Rows[i]["Faci_SystemStatus"].ToString();
itemData.Value = ds.Tables[0].Rows[i]["Faci_SystemStatus"].ToString();

result.Add(itemData);
}

if (ds.Tables[0].Rows.Count > 0)
{
comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), ds.Tables[0].Rows.Count);
}
else
{
comboData.Message = "No matches";
}
}
catch (Exception e)
{
comboData.Message = e.Message;
}

comboData.Items = result.ToArray();
return comboData;
}

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 21 May 2014, 01:22 PM
Hello,

I would suggest using the RadComboBox client-side event function OnClientKeyPressing to prevent typing in the RadComboBox. So basically you can have a Boolean variable that shows whether an item is selected from the drop down list and based on that variable to execute the following code
//JavaScirpt
function OnClientKeyPressing(sender, args) {
   //execute this code block if user is selected an item
    args.get_domEvent().preventDefault();
    args.get_domEvent().stopPropagation()
}

//markup code
<telerik:RadComboBox ID="comsystemstatus" runat="server" EmptyMessage="Select" EnableLoadOnDemand="true" OnClientKeyPressing="OnClientKeyPressing"
          ShowMoreResultsBox="true" AllowCustomText="false"
          EnableVirtualScrolling="true">
          <WebServiceSettings Method="GetItems" Path="WebService.asmx" />
      </telerik:RadComboBox>


Regards,
Boyan Dimitrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Sample Applications
Asked by
Kishore
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or