How to Show Dynamically Genrated RadCombobox In Div.

5 posts, 0 answers
  1. Manish
    Manish avatar
    64 posts
    Member since:
    Jul 2011

    Posted 01 Nov 2011 Link to this post

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

    Posted 01 Nov 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Manish
    Manish avatar
    64 posts
    Member since:
    Jul 2011

    Posted 01 Nov 2011 Link to this post

    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

  5. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 02 Nov 2011 Link to this post

    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.
  6. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 03 Nov 2011 Link to this post

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