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

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

3 Answers 323 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 09 Aug 2012, 07:27 PM
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>

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Aug 2012, 06:28 AM
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.
0
Joshua
Top achievements
Rank 1
answered on 10 Aug 2012, 04:49 PM
Hi Princy,

That doesn't work because i'll be adding like 5 charts and each of them will need their own div.
0
Joshua
Top achievements
Rank 1
answered on 10 Aug 2012, 05:07 PM
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!
Tags
General Discussions
Asked by
Joshua
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Joshua
Top achievements
Rank 1
Share this question
or