Click here to Skip to main content
15,916,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, I can create tab panels in tab container dynamically based on options user has selected from Listbox. Let's say there are 4 items in ListBox, 'Item1, Item2, Item3, Item4'. If user selected all 4 items, 4 tab panels will be created in tab container with header text as 'Item1, Item2, Item3, Item4', which is the option name in Listbox.

I would like to add content like chart to tab panel with specific header text. E.g. to add chart only to tab panel with header text 'Item1" only. How can I accomplish this?

This is my codes to create tab panel dynamically:

Aspx file:
ASP.NET
<asp:listbox ID="SelectionListBox" runat="server" SelectionMode="Multiple" >
<asp:listitem>Select All</asp:listitem>
<asp:listitem>Item 1</asp:listitem>
<asp:listitem>Item 2</asp:listitem>
<asp:listitem>Item 3</asp:listitem>
<asp:listitem>Item 4</asp:listitem>
</asp:listbox>

   <div>
         <asp:scriptmanager ID="ScriptManager1" runat="server">
        </asp:scriptmanager>
    </div>
    <asp:updatepanel ID="UpdatePanel1" runat="server">
        <contenttemplate>

    <asp:placeholder ID="PlaceHolder1" runat="server"></asp:placeholder>
        </contenttemplate>
    </asp:updatepanel>

Cs file:
C#
protected void RETRIEVE_BUTTON_Click(object sender, EventArgs e)
    {
        AjaxControlToolkit.TabContainer container = new AjaxControlToolkit.TabContainer();
        container.ID = DateTime.Now.Millisecond.ToString();
        container.EnableViewState = false;
        container.Tabs.Clear();
        container.Height = Unit.Pixel(500);
        container.Width = Unit.Pixel(1200);
        container.Tabs.AddAt(0, GetManualTab());

        foreach (ListItem item in SelectionListBox.Items)
        {
            if (item.Selected)
            {
                Label tabContent = new Label();
                tabContent.ID = "lbl_tab_";
                tabContent.Text += item.Value;

                AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
                panel.HeaderText += item.Value;
                container.Tabs.Add(panel);
                panel.Controls.Add(tabContent);
            }
        }
        PlaceHolder1.Controls.Add(container);
    }

    public AjaxControlToolkit.TabPanel GetManualTab()
    {
        AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
        return panel;
    }

Question: How to add content like chart to tab panel with specific header text. For example: to add chart only to tab panel with header text 'Item1".

Appreciate if someone can help me on this, thanks a lot!!
Posted
Updated 26-Sep-15 9:26am
v2
Comments
ramyajaya 26-Sep-15 17:16pm    
You can check if the header text is Item1 and add the chart to the tab panel before adding it to the container

Panel.controls. add(chartElement);
container.Tabs.Add(panel)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900