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

Creating Dynamically RadComboBox and Retrieving its value

1 Answer 197 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
DK
Top achievements
Rank 2
DK asked on 21 Dec 2009, 07:49 AM
Hi
I have created radcombobox dynamically.
In a xml file i have defined the name,size of the controls and on that basis i m creating the controls.
controls are created successfully.
now the problem occured when i am retrieving the value.
in the same way i have hae created asp control and i ma able to retrieve their values.
but in case of radcombobox there is error.
I have a asp panel and in that i have a table.
i am adding this control to the table.
I have defined a Table tblControl and finding the value as follows

string ctrlValue=((RadComboBox)tblControl.FindControl("cmbGender")).SelectedItem.Text;

when i debug the code then i fing that  findcontrol returns null.
means control is not availab;e at the server side by the name specified.

please help me in this regard

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Dec 2009, 11:05 AM
Hello,

I tried following code to add RadComboBox in Page_Init event and it works fine. See my code.

CS:
 
    protected void Page_Init(object sender, EventArgs e) 
    { 
        RadComboBox cmbGender= new RadComboBox(); 
        cmbGender.ID= "cmbGender"
        RadComboBoxItem item1 = new RadComboBoxItem("Item1"); 
        RadComboBoxItem item2 = new RadComboBoxItem("Item2"); 
        cmbGender.Items.Add(item1); 
        cmbGender.Items.Add(item2); 
        tblControl.Rows[0].Cells[0].Controls.Add(cmbGender); 
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        string ctrlValue = ((RadComboBox)tblControl.FindControl("cmbGender")).SelectedItem.Text; 
    } 

If you are adding RadComboBox in any postback event, then it wont persist. Could you provide a bit more information about in which event you are trying to add RadComboBox, if this doesn't help?

-Shinu.
Tags
ComboBox
Asked by
DK
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or