Showing posts with label RadComboBox. Show all posts
Showing posts with label RadComboBox. Show all posts

Friday, November 18, 2011

RadComboBox not to select any Item on Load

Problem: I am trying to set SelectedIndex to -1 with the objective that I don't any item in the RadCombo to be highlighted. Whilst the debugger passes the line the next statement says SelectedIndex 0.
How to make the RadCombo not to select any particular item automatically?
Solution: To avoid automatic selection of RadComboBox you can try any of the following approaches.
1) Set EmptyMessage property.
or
2) Add an empty text as first RadComboBoxItem.
Here is the sample ASPX,
<telerik:RadComboBox ID="RadComboBox1" runat="server"
            AutoPostBack="true"  Skin="Sunset" EnableAjaxSkinRendering="false"  >
      <Items>
            <telerik:RadComboBoxItem Text="" Value="-1" />
            <telerik:RadComboBoxItem Text="Telerik School Item 1" Value="0"  >
            </telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="Telerik School Item 2" Value="1">
            </telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="Telerik School Item 3" Value="2">
            </telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="Telerik School Item 4" Value="3">
            </telerik:RadComboBoxItem>
     </Items>     
</telerik:RadComboBox>

RadComboBox EnableLoadOnDemand

Problem: I created radcombobox dynamically. I want to add EnableLoadOnDemand functionality from codebehind. I need a sample of code in asp.net having this functionality doing from codebehind.
Solution: To see how RadComboBox is bound to various data sources, you could refer to the DataBinding section of the Combo's online documentation.

To enable the load on demand functionality, you need to set the property LoadOnDemand to true, and subscribe to the OnItemsRequested server-side event, where the items will be populated when they are requested on demand (which happens when the user opens the drop-down list, or type in the input field), as in the code-block below:
protected void Page_Load(object sender, EventArgs e)
{
    RadComboBox combo = new RadComboBox();
    combo.ID = "RadComboBox1";
    combo.EnableLoadOnDemand = true;
    combo.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(combo_ItemsRequested);
    form1.Controls.Add(combo);
}
protected void combo_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    for (int i = 0; i <= 3; i++)
    {
        combo.Items.Add(new RadComboBoxItem("item_" + i.ToString()));
    }
}

Friday, November 11, 2011

Remove mouse cursor from RadComboBox

Problem: How to remove the blinking mouse cursor from the RadComboBox ?
Solution: You want to prevent to type in RadComboBox. You could try setting AllowCustomText property of the RadComboBox to false which prevents typing any text in the input of the RadComboBox. Also set the EnableLoadOnDemand and MarkFirstMatch properties to false.

Monday, November 7, 2011

How To Get SelectedValue Of RadComboBox From Java Script


Problem: How to get SelectedValue Of RadComboBox using Java Script ?
Solution: Place this Script in the Head tag,

 <script type="text/javascript">
    function GetSelectedValueOfRadComboBox() {
        var radcmb = $find("RadComboBox1");  // Find The Object By  ID 
        var value = radcmb.get_value();  // Get_Value() Is telerik Library Included Function
        Return value;
    }
</script>