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

Beginner's question - RadComboBox value problems

5 Answers 65 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 18 Oct 2012, 09:37 PM
I'm new to RadControls and I'm trying to rough out a simple page using a couple of RadComboBoxes, version 4.0.

First of all I note that there seems to be a great deal of chatter on this forum about bugs in the boxes.

However I wonder if my problem is related or whether I can't use these as ordinary combo boxes.

The code is extremely simple.
I bind it like this:
 cb.DataTextField = "Desc";
 cb.DataValueField = "Id";
 cb.DataBind();

I then hit an ordinary Asp.Net button and try to get the selected values in the click event. 
The data appears to have loaded correctly and the selected text is correct but I cannot get the correct selected value.
I've tried both SelectedValue and SelectedItem.Value.  It's as if it's not setting at all.

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Oct 2012, 05:08 AM
Hi Boris,

RadComboBox performs a Post Back every time a different item is selected and this causes a new page load. When the Load stage of the page life cycle is reached the RadComboBox is rebound, and this action overwrites the previous selected values. You could consider using 2 approaches in order to  resolve this issue. The first one is to bind the control only upon initial load as shown below:

C#:
protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
   RadComboBox1.DataSourceID = SqlDataSource1.ID;
   RadComboBox1.DataTextField = "name";
   RadComboBox1.DataValueField = "name";
   RadComboBox1.DataBind();
  }
}

The second approach is to perform data binding at the Init stage of the life cycle, because at that point the ViewState is still not applied.


Thanks,
Princy.
0
Boris
Top achievements
Rank 1
answered on 19 Oct 2012, 12:24 PM
As I said, I'm new to this version of Rad. 

The AutoPostBack on the control is set to False.  Are you referring to something else? 
0
Nencho
Telerik team
answered on 19 Oct 2012, 03:04 PM
Hi Boris,

Could you provide us the implementation of the RadComboBox that you use at your end. In addition, could you clarify the version of the controls that you are using?

Regards,
Nencho
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
Boris
Top achievements
Rank 1
answered on 22 Oct 2012, 01:06 PM
Implementation?

So far it's just a bare bones Asp.Net screen with a couple of combo boxes on it.

if (!IsPostBack)
 {
     rcb1.DataSource = DataClass1.GetTable();
     rcb1.DataTextField = "Desc";
     rcb1.DataValueField = "Id";
     rcb1.DataBind();
 }
The DataSource is a DataTable.

The Telerik version is 2012.1.501.40,  runtime version: v4.0.30319.
0
Nencho
Telerik team
answered on 23 Oct 2012, 02:00 PM
Hi Boris,

I have prepared sample page for you, implementing the desired functionality. In the provided sample, I use the OnClick event handler of the Button, in order to get the RadComboBox's SelectedValue.


Kind regards,
Nencho
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.
Tags
ComboBox
Asked by
Boris
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Boris
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or