I am using the Combo Box (latest version of ASP.NET AJAX components) and catching the control when the user selects a new item in the list. I need the Value the user selected, NOT the Text, but the new Text appears to be the only I can capture. When the user selects a new item, my code fires properly and I capture e.text, e.oldtext, e.value, and e.oldvalue. When I do this, the e.text and e.oldtext accurately reflect the results, but the e.value and e.oldvalue are identical -- they are both the OLD value.
I have attached a screen capture that shows the results, plus it also shows the contents of the Text/Value pairs that the combo box was loaded with.
The code for the .aspx file is:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LanguageSelector.ascx.cs" Inherits="HomesOnlineNetwork100.UserControls.LanguageSelector" %> <telerik:RadComboBox ID="LanguageSelectorComboBox" runat="server" AutoPostBack="true" onselectedindexchanged="LanguageSelectorComboBox_SelectedIndexChanged" ></telerik:RadComboBox> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="e.Text:"></asp:Label> <asp:Label ID="etext" runat="server" Text="UserLanguageKey"></asp:Label> <br /> <asp:Label ID="Label2" runat="server" Text="e.OldText:"></asp:Label> <asp:Label ID="eoldtext" runat="server" Text="UserLanguageKey"></asp:Label> <br /> <asp:Label ID="Label3" runat="server" Text="e.Value:"></asp:Label> <asp:Label ID="evalue" runat="server" Text="UserLanguageKey"></asp:Label> <br /> <asp:Label ID="Label4" runat="server" Text="e.OldValue:"></asp:Label> <asp:Label ID="eoldvalue" runat="server" Text="UserLanguageKey"></asp:Label> <br /> <br /> <br /> <asp:Label ID="Label5" runat="server" Text="Loaded Text/Values:"></asp:Label> <br /> <asp:Label ID="Label6" runat="server" Text=""></asp:Label> The applicable code for the SelectedIndexChanged is:
protected void LanguageSelectorComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) { Session["a"] = e.Value; Session["b"] = e.OldValue; Session["c"] = e.Text; Session["d"] = e.OldText; The applicable code for the Page_Load event is:
protected void Page_Load(object sender, EventArgs e) { this.evalue.Text = Convert.ToString(Session["a"]); this.eoldvalue.Text = Convert.ToString(Session["b"]); this.etext.Text = Convert.ToString(Session["c"]); this.eoldtext.Text = Convert.ToString(Session["d"]); } Can anyone please tell me why this is happening? I need the new VALUE that the user selected because that is the key to the related database record. Why doesn't the new VALUE come through the event?
My thanks in advance!
Lynn
9 Answers, 1 is accepted
I've prepared a small example page, where you could directly get all the information you need and show it in the labels as it's in your scenario.
You don't need the Session object if it's not a required part of your scenario of course.
Greetings,
Dimitar Terziev
the Telerik team
Thank you for taking the time to respond to my question, but (and no offense intended) you kind of "changed the rules" to come up with an example that would work...Let me explain.
I have a database table that contains (among other fields) an "identity" key column and a name column. I need to populate the combo box with the "Text" = the name column and the "Value" = the key column. When the user selects an item in the combo box (by viewing the name), the code must then obtain the selected key column from the combo box and then read the database record to retrieve other pertinent information. In this situation, the "Text" and the "Value" properties of each combo box item must be different.
In my example, the combo box correctly returned the newly selected "Text" and the old "Text", but erred and returned the old "Value" for the both the new and old settings.
In your example, you "changed these rules" and made the "Text" and "Value" properties the same. Obviously when doing this, the combo box is going to operate fine. You need to make the "Value" properties different from the "Text" values and show me how the combo box works. Personally, I think I need to open a bug report, because that is what this is.
Thanks for your effort.
Lynn
Thank you for contacting us again.
There is no difference whether Text and Value are the same or not. I've prepared another example where the combobox is binded to a DataTable similar to the database you are using, showing you that the values in the labels are populated properly.
I hope this would help.
Best wishes,
Dimitar Terziev
the Telerik team
Which version of Telerik.Web.UI are you using? If you are not using the latest, can you please try with the latest trial to see if the issue exists and send us a sample markup, which reproduces the issue?
Regards,
Simon
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
You can create serival selectItems whose value are diffrent with text. For example, value=1,Text="One".I think it's easy to find out the problem.
Best wishes,
whui
With the latest version of Telerik.Web.UI I loaded up a RadComboBox with the following xml and both the Text and Value properties in the event arguments of the SelectedIndexChanged event handler were correct:
<?xml version="1.0" encoding="utf-8" ?> <Items> <Item Text="One" Value="1" /> <Item Text="Two" Value="2" /> <Item Text="Three" Value="3" /> <Item Text="Four" Value="4" /> <Item Text="Five" Value="5" /></Items>Please let me know if I am missing something and/or provide the markup of a RCB, which reproduces the issue.
Kind regards,
Simon
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!