<
Telerik:radComboBox id="cbPolicyAccountValueSource"
DataTextField="value"
DataValueField="key"
runat="server">
</Telerik:radComboBox>
cbPolicyAccountValueSource.DataSource = LifePolicyAccountValue.PolicyAccountValueSources
cbPolicyAccountValueSource.DataBind()
Dim
PolicyAccountValueSourceEnumId As Object = DataBinder.Eval(DataItem, "PolicyAccountValueSourceEnumId")
cbPolicyAccountValueSource.SelectedValue =
CInt(PolicyAccountValueSourceEnumId)
If I run in debug mode, the above field (PolicyAccountValueSourceEnumId) has the selected value I want the combobox to be selected. But it is not. No item is selected.
What am I doing wrong?
Thanks,
Bob
13 Answers, 1 is accepted
Thank you for writing to us.
Do you execute the code below in the ItemDataBound event handler?
Dim |
PolicyAccountValueSourceEnumId As Object = DataBinder.Eval(DataItem, "PolicyAccountValueSourceEnumId") |
cbPolicyAccountValueSource.SelectedValue = |
CInt(PolicyAccountValueSourceEnumId) |
If this is so, you could skip this step and simply set the selected index or the selected value of the RadComboBox right after you data bind it.
I hope this helps.
Regards,
Simon
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Simon,
I do not use the itemdatabound event. I am doing as you said. I load my radgrid with my data then I try to set the selected row right after it. Here is my code again:
cbPolicy.DataSource = LifePolicye.PolicyAccountValue
cbPolicy.DataBind()
Dim
PolicyId As Object = DataBinder.Eval(DataItem, "PolicyId")
cbPolicy.SelectedValue = CInt(PolicyId)
Like I said, if I debug the above line, PolicyID is the correct value.
Is it possible that the posted code is in the ItemDataBound event handler of some other control which has the RadComboBox in its item template like a RadGrid?
Greetings,
Simon
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Here is my VB.Net code behind:
Partial
Class PolicyValuesDetails
Inherits System.Web.UI.UserControl
Private _dataItem As Object = Nothing
#Region
"Web Form Designer generated code"
Protected Overrides Sub OnInit(ByVal e As EventArgs)
'
' CODEGEN: This call is required by the ASP.NET Web Form Designer.
'
InitializeComponent()
MyBase.OnInit(e)
End Sub 'OnInit
'/ <summary>
'/ Required method for Designer support - do not modify
'/ the contents of this method with the code editor.
'/ </summary>
Private Sub InitializeComponent()
AddHandler DataBinding, AddressOf Me.PolicyValuesDetails_DataBinding
End Sub 'InitializeComponent
#End
Region
Public Property DataItem() As Object
Get
Return Me._dataItem
End Get
Set(ByVal value As Object)
Me._dataItem = value
End Set
End Property
Protected Sub PolicyValuesDetails_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
cbPolicyAccountValueSource.DataSource = LifePolicyAccountValue.PolicyAccountValueSources
cbPolicyAccountValueSource.DataBind()
cbPolicyAccountValueSource.SelectedValue = DataBinder.Eval(DataItem,
"PolicyAccountValueSourceEnumId")
End Sub
End
Class
Here is my ASCX code for the radComboBox:
<
telerik:RadComboBox ID="cbPolicyAccountValueSource"
TabIndex="2"
DataTextField="value"
DataValueField="key"
runat="server">
</telerik:RadComboBox>
This line of VB.Net.
cbPolicyAccountValueSource.SelectedValue = DataBinder.Eval(DataItem, "PolicyAccountValueSourceEnumId")
is where I want to set the selectedvalue. In debug mode, DataBinder.Eval(DataItem, "PolicyAccountValueSourceEnumId")
= 2 which is correct. But the first value is always selected.
I stripped out all the AJAX stuff too thinking this was the problem. But it still does not work. Please note that this is a user control that displays when the Edit button is clicked on a radGrid which resides in another user control. It is impossible to send you a working version since my client will not allow it. But I do not understand why this does not work. When I try to set the SelectedValue with the correct value, it just does not work.
Thanks,
Bob
Thank you for providing the additional code.
You could try assigning an empty data source to the RadComboBox control at the end of the DataBinding routine, like this:
Protected Sub PolicyValuesDetails_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) |
cbPolicyAccountValueSource.DataSource = LifePolicyAccountValue.PolicyAccountValueSources |
cbPolicyAccountValueSource.DataBind() |
cbPolicyAccountValueSource.SelectedValue = DataBinder.Eval(DataItem, |
"PolicyAccountValueSourceEnumId") |
cbPolicyAccountValueSource.DataSource = Nothing |
End Sub |
You could read this online help article for more information - Custom Edit Forms and more specifically the "Binding selected values for MS DropDownLists when having user control custom edit form" section.
Please let me know how it goes.
Sincerely yours,
Simon
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thanks Simon.
Bob
I am also facing the same problem with RadComboBox.
Problem is By RadListView Selection Radcombobox selected value is to be change but it is not working.
Please have a look into the sample code snippet which works fine at my end.
ASPX:
<
telerik:RadListView
ID
=
"RadListView1"
Width
=
"97%"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
ItemPlaceholderID
=
"ProductsHolder"
DataKeyNames
=
"ProductID"
OnItemDataBound
=
"RadListView1_ItemDataBound"
>
<
LayoutTemplate
>
<
fieldset
style
=
"max-width: 920px;"
id
=
"FieldSet1"
>
<
legend
>Products</
legend
>
<
asp:Panel
ID
=
"ProductsHolder"
runat
=
"server"
/>
</
fieldset
>
</
LayoutTemplate
>
<
ItemTemplate
>
<
telerik:RadComboBox
ID
=
"radcboSelectedValue"
runat
=
"server"
>
</
telerik:RadComboBox
>
</
ItemTemplate
>
</
telerik:RadListView
>
C#:
protected
void
RadListView1_ItemDataBound(
object
sender, RadListViewItemEventArgs e)
{
RadComboBox selectCombo = e.Item.FindControl(
"radcboSelectedValue"
)
as
RadComboBox;
selectCombo.DataSource =
"SqlDataSource1"
;
selectCombo.DataBind();
selectCombo.DataValueField =
"ProductID"
;
selectCombo.SelectedItem.Text =
"3"
;
selectCombo.DataSource =
null
;
}
Let me know if you have any concern.
Thanks,
Shinu.
By clicking button another user control visible true and it has radcombobox with databind method.
What happen is at first time clicked row button of listview is selected in visibled radcombobox.
But second time not changes the value of radcombobox of usercontrol.
RadCombobox SelectedItems(Text and value) changes every time based on listview but Text is not changes .
My code works fine with asp:dropdownlist but i am to use RadCombobox Please help me out.
Please have a look into the sample code snippet which works fine at my end. Please provide your full code if it doesn't help.
ASPX:
<
uc1:ListViewControl
ID
=
"ListViewControl1"
runat
=
"server"
/>
ListViewUserControl.ASCX:
<
telerik:RadListView
ID
=
"radlstviewServerBind"
runat
=
"server"
ItemPlaceholderID
=
"ProductsHolder"
OnNeedDataSource
=
"radlstviewServerBind_NeedDataSource"
>
<
LayoutTemplate
>
<
fieldset
style
=
"max-width: 920px;"
id
=
"FieldSet1"
>
<
legend
>Products</
legend
>
<
asp:Panel
ID
=
"ProductsHolder"
runat
=
"server"
/>
</
fieldset
>
</
LayoutTemplate
>
<
ItemTemplate
>
<
telerik:RadButton
ID
=
"radbtnShowCombo"
runat
=
"server"
Text
=
"Apply"
OnClick
=
"radbtnShowCombo_Click"
>
</
telerik:RadButton
>
</
ItemTemplate
>
</
telerik:RadListView
>
ListViewUserControl C#:
protected
void
radlstviewServerBind_NeedDataSource(
object
sender, Telerik.Web.UI.RadListViewNeedDataSourceEventArgs e)
{
radlstviewServerBind.DataSourceID =
"SqlDataSource1"
;
}
protected
void
radbtnShowCombo_Click(
object
sender, EventArgs e)
{
UserControl control = LoadControl(
"ComboBox.ascx"
)
as
UserControl;
this
.Controls.Add(control);
RadComboBox combo = control.FindControl(
"radcboSelectedValue"
)
as
RadComboBox;
//here you can select the item of the RadComboBox
combo.SelectedValue =
"10259"
;
}
ComboBox.ASCX:
<
telerik:RadComboBox
ID
=
"radcboSelectedValue"
runat
=
"server"
DataSourceID
=
"SqlDataSource2"
DataValueField
=
"OrderID"
DataTextField
=
"CustomerID"
>
</
telerik:RadComboBox
>
Thanks,
Shinu.