People, can you help to select radcombo item in server side?
Look in my example
drpActive.SelectedValue = 2;
When I try this example above, RadComboBox does not select the element.
Can you help me to solve this, please?
Best Regards,
Milton Camara
Look in my example
drpActive.SelectedValue = 2;
When I try this example above, RadComboBox does not select the element.
Can you help me to solve this, please?
Best Regards,
Milton Camara
3 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 28 Dec 2011, 05:55 AM
Hello Milton,
Try any of the following approaches:
C#:
Thanks,
Shinu.
Try any of the following approaches:
C#:
if
(!Page.IsPostBack)
{
RadComboBox1.Text =
"Text2"
;
}
//or
if
(!Page.IsPostBack)
{
int
index = RadComboBox1.FindItemIndexByValue(
"<combo_item_value>"
);
RadComboBox1.SelectedIndex = index;
}
//or
if
(!Page.IsPostBack)
{
RadComboBoxItem item = RadComboBox1.FindItemByText(
"<combo_item_text>"
);
item.Selected =
true
;
}
Thanks,
Shinu.
Milton
commented on 28 Dec 2011, 04:43 PM
Top achievements
Rank 1
Its not work yet. As I see in SelectedIndex or SelectedValue is a property ReadOnly without a Set method.
Understand me?
Understand me?
0

Richard
Top achievements
Rank 1
answered on 29 Dec 2011, 03:46 PM
Milton:
Take a look at this code. It gets the "Paris" droplist option that is defined with an initial value of "2" in the "combobox.xml" and it resets the value to "0" using the server-side "PageLoad" event:
Note that the selectedvalue set takes a string value, not an integer.
Default.aspx:
C#
combobox.xml:
Take a look at this code. It gets the "Paris" droplist option that is defined with an initial value of "2" in the "combobox.xml" and it resets the value to "0" using the server-side "PageLoad" event:
Note that the selectedvalue set takes a string value, not an integer.
Default.aspx:
<
div
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
Height
=
"140px"
Width
=
"210px"
>
</
telerik:RadComboBox
>
</
div
>
C#
using
System;
using
Telerik.Web.UI;
public
partial
class
Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
RadComboBox1.LoadContentFile(
"combobox.xml"
);
//// Selects 'Paris" from droplist by index #
//RadComboBox1.SelectedIndex = 1;
//// Selects 'Paris" from droplist by assigned value
//RadComboBox1.SelectedValue = "2";
// Assigns a new value to 'Paris' droplist option
RadComboBoxItem item1 = RadComboBox1.FindItemByValue(
"2"
);
item1.Value =
"0"
;
// Selects 'Paris" from droplist by assigned value
RadComboBox1.SelectedValue =
"0"
;
}
}
combobox.xml:
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
Items
>
<
Item
Text
=
"New York"
Value
=
"1"
/>
<
Item
Text
=
"Paris"
Value
=
"2"
/>
<
Item
Text
=
"London"
Value
=
"3"
/>
<
Item
Text
=
"Oslo"
Value
=
"4"
/>
<
Item
Text
=
"Sofia"
Value
=
"5"
/>
<
Item
Text
=
"Liverpool"
Value
=
"6"
/>
<
Item
Text
=
"Seattle"
Value
=
"7"
/>
<
Item
Text
=
"San Francisco"
Value
=
"8"
/>
<
Item
Text
=
"Boston"
Value
=
"9"
/>
<
Item
Text
=
"Miami"
Value
=
"10"
/>
<
Item
Text
=
"Denver"
Value
=
"11"
/>
<
Item
Text
=
"Dallas"
Value
=
"12"
/>
<
Item
Text
=
"Madrid"
Value
=
"13"
/>
<
Item
Text
=
"Barcelona"
Value
=
"14"
/>
<
Item
Text
=
"Amsterdam"
Value
=
"15"
/>
<
Item
Text
=
"Moscow"
Value
=
"16"
/>
<
Item
Text
=
"Brussels"
Value
=
"17"
/>
<
Item
Text
=
"Bonn"
Value
=
"18"
/>
<
Item
Text
=
"Dublin"
Value
=
"19"
/>
<
Item
Text
=
"St.Paul"
Value
=
"20"
/>
</
Items
>
Melchor
commented on 28 Aug 2019, 05:26 PM
Top achievements
Rank 1
It is an old post, but it helps someone else, this happened to me but was because I had EnableAutomaticLoadOnDemand set to true, so the items did not exists until the controls was clickced
Johnny
commented on 18 Aug 2023, 01:53 PM
Top achievements
Rank 3
Bronze
Iron
Iron
I can confirm that as well.
0

Johnny
Top achievements
Rank 3
Bronze
Iron
Iron
answered on 18 Aug 2023, 01:55 PM
| edited on 18 Aug 2023, 01:55 PM
Although this is an old post, but this can still be helpful to some people.
One of the solutions to be able to select an item from the ComboBox on page_load for example, is to disable the property EnableAutomaticLoadOnDemand.
Example:
<telerik:RadComboBox ID="rcb_typeAction" runat="server" Skin="Material" AppendDataBoundItems="true" EnableLoadOnDemand="false" EnableAutomaticLoadOnDemand="false">
<Items>
<telerik:RadComboBoxItem runat="server" Text="Visite" Value="Visite" />
<telerik:RadComboBoxItem runat="server" Text="Appel Téléphonique" Value="Appel Téléphonique" />
<telerik:RadComboBoxItem runat="server" Text="Email" Value="Email" />
<telerik:RadComboBoxItem runat="server" Text="À Distance" Value="À Distance" />
</Items>
</telerik:RadComboBox>