How to add a div elemental dynamically when you add a control.

4 posts, 0 answers
  1. Joshua
    Joshua avatar
    35 posts
    Member since:
    May 2012

    Posted 09 Aug 2012 Link to this post

    I have a MultiPage, and what I do is add a couple RadChart dynamically.


    What I want to be able to do is surround each of these charts with a div.  Below is the code i'm using, if anybody has an example that would be fantastic!

    <div class ="ChartClass"></div>
    MultiPage.FindPageViewByID(MultiTabTarget).Controls.Add(RChart);

    so i'd want
    <div class="ChartClass">
    RChart
    </div>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Aug 2012 Link to this post

    Hi Joshua,

    I suppose you want to add control to div dynamically. One suggestion is that you can add the id and runat attributes to the div and can add RadChart to the div. Following is the sample code.

    ASPX:
    <div id="div1" runat="server" class ="ChartClass"></div>

    C#:
    MultiPage.FindPageViewByID(MultiTabTarget).Controls.Add(div1);
    div1.Controls.Add(RChart);

    Hope this helps.

    Regards,
    Princy.
  3. Joshua
    Joshua avatar
    35 posts
    Member since:
    May 2012

    Posted 10 Aug 2012 Link to this post

    Hi Princy,

    That doesn't work because i'll be adding like 5 charts and each of them will need their own div.
  4. Joshua
    Joshua avatar
    35 posts
    Member since:
    May 2012

    Posted 10 Aug 2012 Link to this post

    private void CreateDivforCharts(string MultiTabTarget, RadChart RChart)
        {
            HtmlGenericControl div = new HtmlGenericControl("div");
            div.Attributes.Add("class", "ChartClass");
            CarLotMultiPage.FindPageViewByID(MultiTabTarget).Controls.Add(div);
            div.Controls.Add(RChart);
        }

    works!
Back to Top