felicia tan
asked on
Create Tabs Dynamically Based on Values Selected in Listbox in ASP.Net
Hi, does anyone know how can I create tabs dynamically based on what is selected from a Listbox?
This is what I have:
Listbox:
<asp:ListBox ID="SelectionListBox" runat="server" AppendDataBoundItems="True " SelectionMode="Multiple" Height="130px" Width="350px">
<asp:ListItem Text="Apple" Value ="1" />
<asp:ListItem Text="Watermelon" Value ="2" />
<asp:ListItem Text="Kiwi" Value ="3" />
<asp:ListItem Text="Plum" Value ="4" />
<asp:ListItem Text="Pineapple" Value ="5" />
</asp:ListBox>
RetrieveButton:
<asp:Button ID="RetrieveButton" runat="server" Text="Button" />
Based on what the user has selected from the Listbox, when the user pressed on the Retrieve button, number of tabs will be created based on the number of values user has selected from Listbox.
For example:
Let's say user has selected 3 items from the Listbox and click on the button, 3 tabs should be created at the bottom of the page on the same page with the tab names as the Listbox items texts.
Please refer to file attached for sample output illustration.
Any help is greatly appreciated. Thanks!
OutputTab.png
This is what I have:
Listbox:
<asp:ListBox ID="SelectionListBox" runat="server" AppendDataBoundItems="True
<asp:ListItem Text="Apple" Value ="1" />
<asp:ListItem Text="Watermelon" Value ="2" />
<asp:ListItem Text="Kiwi" Value ="3" />
<asp:ListItem Text="Plum" Value ="4" />
<asp:ListItem Text="Pineapple" Value ="5" />
</asp:ListBox>
RetrieveButton:
<asp:Button ID="RetrieveButton" runat="server" Text="Button" />
Based on what the user has selected from the Listbox, when the user pressed on the Retrieve button, number of tabs will be created based on the number of values user has selected from Listbox.
For example:
Let's say user has selected 3 items from the Listbox and click on the button, 3 tabs should be created at the bottom of the page on the same page with the tab names as the Listbox items texts.
Please refer to file attached for sample output illustration.
Any help is greatly appreciated. Thanks!
OutputTab.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Let's say if there is 5 columns in the grid view and I just want to look into the values from the 'Product' column, I want to check whether there is matching values between the values from the 'Product' column and all tab panels' header text. All tab panels' header text is distinct from each other. If there is matching values, then the row from the grid view that has matching value will be added to the tab panel that has the same value as its header text.
This is my code:
.aspx code:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:Scrip
<asp:ListBox ID="SelectionListBox" runat="server" AppendDataBoundItems="True
<asp:ListItem Text="Apple" Value ="1" />
<asp:ListItem Text="Watermelon" Value ="2" />
<asp:ListItem Text="Kiwi" Value ="3" />
<asp:ListItem Text="Plum" Value ="4" />
<asp:ListItem Text="Pineapple" Value ="5" />
<asp:Button ID="RetrieveButton" runat="server" Height="40px" Text="Retrieve" Width="130px" OnClick="RETRIEVE_BUTTON_C
<asp:GridView ID="SelectionGridView" runat="server" AllowSorting="True" AutoGenerateColumns="False
<AlternatingRowStyle BackColor="White" />
<columns>
<asp:boundfield DataField="Date" HeaderText="Date"></asp:bo
<asp:boundfield DataField="Customer_ID" HeaderText="Customer ID"></asp:boundfield>
<asp:boundfield DataField="Customer_Name" HeaderText="Customer Name"></asp:boundfield>
<asp:boundfield DataField="Age" HeaderText="Age"></asp:bou
<asp:boundfield DataField="Product" HeaderText="Product"></asp
</columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="False" ForeColor="Black" />
<HeaderStyle BackColor="#507CD1" Font-Bold="False" ForeColor="Black" BorderStyle="Solid" BorderWidth="2px" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="False" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyl
<SortedDescendingCellStyle
<SortedDescendingHeaderSty
</asp:GridView>
<asp:Panel ID="panel1" runat="server" Width="100%"></asp:Panel>
.cs code:
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
namespace TestWebApplication
{
public partial class WebForm1 : System.Web.UI.Page
{
TabContainer TabContainer1= new TabContainer();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RetrieveButton_Click(objec
{
var query = from ListItem item in SelectionListBox.Items where item.Selected select item;
var query1 = query.ToList();
var count = query1.Count();
string[] arr = new string[count];
int i=0;
foreach (ListItem item in query)
{
arr[i] = item.Text;
i++;
}
for( int j =0; j <arr.Length;j++)
{
//Response.Write(s + "<br/>");
TabPanel panel = new TabPanel();
panel.HeaderText = arr[j].ToString();
panel.ID = arr[j].ToString() + j;
TabContainer1.Tabs.Add(pan
}
panel1.Controls.Add(TabCon
}
}
}
Would appreciate if you could help me on this, thank you very much!