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

RadComboBox Selected Item

3 Answers 289 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Johnny
Top achievements
Rank 2
Johnny asked on 10 Jan 2012, 07:32 AM
hi i dynamically create RadComboBox and fill items then set SelectedItem if the SelectedItem Exist on the database
next time i click another link on again i clear all dynamic items again i create dynamic controls
but the problem is second time created Combobox holds the selectedItem of First time created Combobox
how to solve this problem?

3 Answers, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 12 Jan 2012, 02:58 PM
Hi Johnny,

You could save the value of the previously selected item in a hidden field. Then, on pageLoad event, you could get the information about the item from the hidden field, and set that item as selected.

The most appropriate moment to save information about the currently selected item is on the SelectedIndexChanged server or client-side event.

Regards,
Ivana
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
Johnny
Top achievements
Rank 2
answered on 13 Jan 2012, 05:00 AM
hi ivana u misunderstood my Proble
ok for example there got 2 link in my web page A and B
if i click A
dynamically add a RadDropDown then add items
aa
bb
cc
then set selectedItem aa

if i click B
dynamically add a RadDropDown (with same Id Previously created) then add items
aa
bb
cc
then set selectedItem bb

but the RadDropdown still hold the selectedItem aa


0
Princy
Top achievements
Rank 2
answered on 13 Jan 2012, 07:11 AM
Hello,

Try the following.
ASPX:
<asp:LinkButton ID="LinkButton1" runat="server" Text="A" OnClick="LinkButton1_Click"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" Text="B" OnClick="LinkButton2_Click"></asp:LinkButton>
C#:
protected void LinkButton1_Click(object sender, EventArgs e)
   {
       RadComboBox combob = new RadComboBox();
       combob.ID = "combo1";
       RadComboBoxItem itm1 = new RadComboBoxItem();
       itm1.Text = "aa";
       itm1.Value = "1";
       combob.Items.Add(itm1);
       RadComboBoxItem itm2 = new RadComboBoxItem();
       itm2.Text = "bb";
       itm2.Value = "2";
       combob.Items.Add(itm2);
       RadComboBoxItem itm3 = new RadComboBoxItem();
       itm3.Text = "cc";
       itm3.Value = "3";
       combob.Items.Add(itm3);
       form1.Controls.Add(combob);
       combob.SelectedValue = "1";
   }
   protected void LinkButton2_Click(object sender, EventArgs e)
   {
       RadComboBox combob = new RadComboBox();
       combob.ID = "combo1";
       RadComboBoxItem itm1 = new RadComboBoxItem();
       itm1.Text = "aa";
       itm1.Value = "1";
       combob.Items.Add(itm1);
       RadComboBoxItem itm2 = new RadComboBoxItem();
       itm2.Text = "bb";
       itm2.Value = "2";
       combob.Items.Add(itm2);
       RadComboBoxItem itm3 = new RadComboBoxItem();
       itm3.Text = "cc";
       itm3.Value = "3";
       combob.Items.Add(itm3);
       form1.Controls.Add(combob);
       combob.SelectedValue = "2";
   }

Thanks,
Princy.
Tags
ComboBox
Asked by
Johnny
Top achievements
Rank 2
Answers by
Ivana
Telerik team
Johnny
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or