When adding the items in the ItemsRequested event (via callback), the items are actually added only on the client-side. They are not visible on the server-side. This is due to the AJAX async. requests. Therefore, the RadComboBox.SelectedItem and RadComboBox.SelectedValue properties are null in the ItemsRequested event.
To get the text and the value of the selected item in the ItemsRequested event, you should use the following syntax:
Example:
| ASPX |
Copy Code |
|
<rad:RadComboBox id= "RadComboBox1" runat= "server" OnItemsRequested= "RadComboBox1_ItemsRequested" EnableLoadOnDemand= "True"> </rad:RadComboBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="GetSelectedTextAndValue" /> |
| C# |
Copy Code |
|
protected void RadComboBox1_ItemsRequested(object o, Telerik.WebControls.RadComboBoxItemsRequestedEventArgs e) { RadComboBox1.Items.Add(new RadComboBoxItem("Item1", "1")); RadComboBox1.Items.Add(new RadComboBoxItem("Item2", "2")); RadComboBox1.Items.Add(new RadComboBoxItem("Item3", "3")); } protected void Button1_Click(object sender, EventArgs e) { String SeledtedText = RadComboBox1.Text; String SelectedValue = RadComboBox1.Value; } |
| VB.NET |
Copy Code |
|
Protected Sub RadComboBox1_ItemsRequested(o As Object, e As Telerik.WebControls.RadComboBoxItemsRequestedEventArgs) RadComboBox1.Items.Add(New RadComboBoxItem("Item1", "1")) RadComboBox1.Items.Add(New RadComboBoxItem("Item2", "2")) RadComboBox1.Items.Add(New RadComboBoxItem("Item3", "3")) End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Dim SeledtedText As [String] = RadComboBox1.Text Dim SelectedValue As [String] = RadComboBox1.Value End Sub |