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

How to Show Dynamically Genrated RadCombobox In Div.

4 Answers 67 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Manish
Top achievements
Rank 2
Manish asked on 01 Nov 2011, 07:46 AM
Hi,

My requirement is :

I am generating a div on button click and i want a dynamically generated rad combo box in that div. I am able to create a div and rad combo box but not able to put it in the div. Please check my code and provide some solution. Please i need solution as soon as possible.

.ASPX Page
My button :
 <asp:Button runat="server" ID="btnAddDiv" ToolTip="+ Add Clause(s)" Text="+"
            CssClass="btnAdd" onclick="btnAddDiv_Click"/>
Div :
<div id="testing" runat="server"></div>

.ASPX.CS Page

int Counter =0;
  protected void btnAddDiv_Click(object sender, EventArgs e)
        {

            RadComboBox Box = new RadComboBox();
            Box.ID = "RCB" + Counter;
            Box.DataSource = ObjGetData.GetClause();
            Box.DataValueField = "ClauseHeadingID";
            Box.DataTextField = "ClauseHeadingType";
            Box.DataBind();
            testing.InnerHtml = testing.InnerHtml + "<div id='text" + Counter + "'> " + I WANT TO SHOW MY COMBO BOX HERE +"</div>";
            
            Counter += 1;

        }
 
I am doing this because i want to generate this div with combo box according to user dynamically and user can generate it infinite time.

Note: ignore my cap words. I just want to highlight my requirement.

Thanks
Manish

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Nov 2011, 09:00 AM
Hello Manish,

You can add the RadComboBox in div as shown below.
C#:
protected void Button1_Click(object sender, EventArgs e)
{
  RadComboBox combo = new RadComboBox();
    . . .    
  testing.Controls.Add(combo);
}

-Shinu.
0
Manish
Top achievements
Rank 2
answered on 01 Nov 2011, 09:53 AM
Thanks for your Reply but I need to put Radcombo box in Dynamically generated div as i have asked. So the problem is that when i am generating the div on that time how can i get the id of div to use

Problem : I have a Div name "testing" and in that i am adding another inner div dynamically

testing.InnerHtml = testing.InnerHtml + "<div id='text" + Counter + "'> " + I WANT TO SHOW MY COMBO BOX HERE +"</div>";

so Please tell the actual solution.

you answer is right but in my case i need according to my condition

Please see my code once. You will understand my My Problem. Please.

Thanks
Manish

0
Kevin
Top achievements
Rank 2
answered on 02 Nov 2011, 01:46 PM
Hello Manish,

To expand on Shinu's solution, this is how you would add a div and the RadComboBox to the testing div.

HtmlGenericControl divText = new HtmlGenericControl("div");
        divText.ID = string.Format("text{0}", Counter);
  
        RadComboBox combo = new RadComboBox();
        . . .
        divText.Controls.Add(combo);
        testing.Controls.Add(divText);

You have to create a div control for the inner div and add the RadComboBox to that and then add the inner div to the testing div. You can use InnerHtml because that only accepts text and ASP.NET controls are not text and cannot be added as such.

I hope that helps.
0
Ivana
Telerik team
answered on 03 Nov 2011, 10:43 AM
Hi Manish,

Here is an example how the described scenario could be achieved:
<asp:Button ID="Button1" Text="Click Me" runat="server" onclick="Button1_Click"/>
<div id="outerDiv" runat="server">
</div>
protected void Button1_Click(object sender, EventArgs e)
{
    HtmlGenericControl divText = new HtmlGenericControl("div");
    divText.ID="innerDiv";
         
    RadComboBox combo = new RadComboBox();
    RadComboBoxItem item1 = new RadComboBoxItem("item1");
    combo.Items.Add(item1);
 
    divText.Controls.Add(combo);
 
    outerDiv.Controls.Add(divText);
}

Hope this helps.

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
Tags
ComboBox
Asked by
Manish
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Manish
Top achievements
Rank 2
Kevin
Top achievements
Rank 2
Ivana
Telerik team
Share this question
or