Creating Dynamically RadComboBox and Retrieving its value

2 posts, 0 answers
  1. DK
    DK avatar
    72 posts
    Member since:
    Jun 2009

    Posted 21 Dec 2009 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Dec 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top