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

Reuse ComboBox

4 Answers 56 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 25 Aug 2008, 03:27 PM
I'm usnig your RadCOmboBox on several of my pages.  It is the same in all pages "Users"  How can I make it so that the code behind is reused for the one dropdownlist?  Also, how do I access the dropdown items in the events of the code behind like Button_OnClick ?

4 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 26 Aug 2008, 07:16 AM
Hello George,

I suggest you place the RadComboBox in an User Control and use this user control where you need id.

As for accessing items you can use the Items property of RadComboBox . For example to access the first item you can use the following code:

C#
string itemtext = RadComboBox1.Items[0].Text; 

VB
Dim itemtext As String = RadComboBox1.Items(0).Text  
 

More about RadComboBox you can find in our online help documentation.


Regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 26 Aug 2008, 01:28 PM
I am using Q2 2008 ASP.NET AJAX and wondering why this error is happening when trying to access the dropdownlist

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'ASP.controls_dropdownlist_ascx' does not contain a definition for 'SelectedValue' and no extension method 'SelectedValue' accepting a first argument of type 'ASP.controls_dropdownlist_ascx' could be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 129: if (!String.IsNullOrEmpty(Convert.ToString(RadComboBox1.SelectedValue)))Line 130:        {
Line 131:            if (Convert.ToInt32(RadComboBox1.SelectedValue) == (int)Enumeration.HasValue.No)

This is also not working. :(
string itemtext = RadComboBox1.Items[0].Text;  
0
Rosi
Telerik team
answered on 26 Aug 2008, 02:18 PM
Hello George,

The reason for the error is the way you access the combobox. Please find the sample project which works as expected.

Regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 26 Aug 2008, 03:16 PM
Rosi,
I don't want this in my page_load

 protected void Page_Load(object sender, EventArgs e)  
    {  
        RadComboBox combo1 = (RadComboBox)WebUserControl1.FindControl("RadComboBox1");  
        string itemText = combo1.Items[0].Text;  
        Response.Write(itemText);  
    } 

I want to have it in the Search Method passing the arguments and it is always sending the default item even when I select something else in the dropdownlist.  Is it because I am using AJAX ASP.NET ?
Tags
ComboBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Mike
Top achievements
Rank 1
Share this question
or