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

RadComboBox Value Property

8 Answers 485 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
JJ
Top achievements
Rank 1
JJ asked on 25 Jan 2008, 08:11 PM
How do I set the 'Value' property on my item?  I see that the 'Text' property is available, but no 'Value'.

Thanks,

Jeff

8 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 28 Jan 2008, 03:29 PM
Hi Jeff Johnson,

The 'Text' property of the RadComboBox refers to the text which is displayed in the text area of the control. The control does not have a corresponding 'Value' property. Still, each of its Items has a 'Value' property and it can be set either for the currently selected item (RadComboBox.SelectedItem.Value) or for a specific one through the RadComboBox 'Items' collection (RadComboBox.Items[i].Value).

All the best,
Simeon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Hoon
Top achievements
Rank 1
answered on 29 Dec 2010, 12:13 AM
http://www.telerik.com/help/aspnet/combobox/comboitemsrequested.html

I'm sorry but your explanation is inconsistent as above. How can I acess the selectedvalue after bindingdata with itemsrequested.
0
msigman
Top achievements
Rank 2
answered on 29 Dec 2010, 04:14 AM
Are you trying to access the SelectedValue, or set it?  In your first post you said set it, but in the second you ask how to access it...

You access it by using ComboBox.SelectedValue;

And you set it by using DataValueField and then DataBind()ing.
0
Tim
Top achievements
Rank 1
answered on 02 Mar 2012, 10:27 PM
Was there a solution here to the scenario that Hoon brought up?  I have the exact same issue with the ‘Value’ property missing and not allowing me to assign a value when I handle the OnItemsRequested event.  This worked in one of the 2008 versions of ASP.NET.
0
msigman
Top achievements
Rank 2
answered on 04 Mar 2012, 10:39 PM
Hi Tim,

What about using ComboBox.SelectedItem.Value?
0
Simon
Telerik team
answered on 08 Mar 2012, 05:29 PM
Hi Tim,

The help article, which Hoon referred to, is for RadComboBox for ASP.NET and we are discussing here the AJAX version of the same control. The Value property has been deprecated when the controls were migrated to the the ASP.NET AJAX Framework.

One way to work around this limitation is to have a hidden field next to the combobox and on each SelectedIndexChanged event of the latter to set the value of the selected item as value of the hidden field. This way you can obtain the selected item's value on the server after postback.

Kind regards,
Hector
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tim
Top achievements
Rank 1
answered on 10 Apr 2012, 08:28 PM
One of the issues would be getting the value (not just the text) and this workaround would indeed be a solution.  However, I need to be able to store both a string in the control and an index (integer) in the control.  Am I missing something?  This RadComboBox is being used within a RadGrid when using the edit template and the databinding is being loaded in the code-behind. 

So at this point, this control appears to be a singular data element combo box and I'm not sure how valuable it really is to other developers.  If you can't store both an index and a useful string to the UI, how can this be used in a database driven environment?

The only solution I currently see is to append my index onto the string with a separator character.  But with this solution, I'll have to intercept the Insert/Update SQL command and split this out - all of which just seems like too much work.

 

 

<telerik:GridTemplateColumn UniqueName="AttendeeName" HeaderText="Attendee Name" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" DataField="AttendeeName" Visible="true">

 

 

 

<ItemTemplate>

 

 

 

<asp:Label runat="server" ID="lblAttendeeID" Text='<%# Bind("AttendeeID") %>' visible="false"></asp:Label>

 

 

 

<asp:Label runat="server" ID="lblAttendeeName" Text='<%# Bind("AttendeeName") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

<EditItemTemplate>

 

 

 

<telerik:RadComboBox ID="cmdHost1" runat="server" Width="150px" Height="120px" Value='<%# Bind("AttendeeID") %>' Text='<%# Bind("AttendeeName") %>'

 

 

 

Skin="Office2010Black" AutoPostBack="True" AllowCustomText="True" ShowToggleImage="False"

 

 

 

EnableLoadOnDemand="True" MarkFirstMatch="False" OnItemsRequested="cmdHost1_ItemsRequested" >

 

 

 

</telerik:RadComboBox>

 

 

 

</EditItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

Protected Sub cmdHost1_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)

 

 

 

Dim [text] As String = e.Text

 

 

 

Dim conn1 As SqlConnection = Nothing

 

 

 

Dim oRD As SqlDataReader = Nothing

 

 

 

Dim cmd As SqlCommand = Nothing

 

 

 

Dim combo As RadComboBox = Nothing

 

 

 

Try

 

combo =

 

CType(o, RadComboBox)

 

combo.Items.Clear()

conn1 =

 

New SqlConnection(ConfigurationManager.ConnectionStrings("DS1").ConnectionString)

 

conn1.Open()

cmd =

 

New SqlCommand()

 

cmd.Connection = conn1

cmd.CommandText =

 

"SELECT EmployeeID, DisplayName FROM MeetingList WHERE DisplayName LIKE '" + [text].Replace("'", "''") + "%' ORDER BY DisplayName"

 

cmd.CommandType =

 

CommandType.Text

 

oRD = cmd.ExecuteReader()

 

 

Do While oRD.Read()

 

 

 

If oRD.HasRows Then

 

 

 

Try

 

 

 

Dim item As New RadComboBoxItem(oRD.Item("DisplayName").ToString().ToLower())

 

item.Value = oRD.Item(

 

"EmployeeID").ToString()

 

item.Text = oRD.Item(

 

"DisplayName").ToString()

 

combo.Items.Add(item)

 

 

Catch ex As Exception

 

 

 

End Try

 

 

 

End If

 

 

 

Loop

 

oRD.Close()

 

 

Catch ex As Exception

 

 

 

If Not oRD Is Nothing AndAlso Not oRD.IsClosed Then oRD.Close()

 

 

 

Finally

 

 

 

If conn1 IsNot Nothing Then conn1.Close()

 

 

 

End Try

 

 

 

End Sub

 

Parser Error Message: Two-way binding is only supported for properties. 'Value' is not a valid property on 'RadComboBox'


0
Tim
Top achievements
Rank 1
answered on 10 Apr 2012, 09:17 PM
After reviewing some other examples, in my own code nonetheless, I am indeed missing some key points.   Here was how I implemented the solution:

 

 

Protected Sub cmdHost1_OnSelectedIndexChange(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)

 

 

 


Dim
valueLabel As Label = DirectCast(RadGrid1.MasterTableView.GetInsertItem("AttendeeName").FindControl("lblValue"), Label)

 

valueLabel.Text = e.Value

 

 

End Sub

Tags
ComboBox
Asked by
JJ
Top achievements
Rank 1
Answers by
Simon
Telerik team
Hoon
Top achievements
Rank 1
msigman
Top achievements
Rank 2
Tim
Top achievements
Rank 1
Share this question
or