I have i listbox inside a user control which is dynamically created on page_init. I check for postback and only populate the datasource if it's false. regardless, i do this
Expand|Select|Wrap|Line Numbers
- foreach (Product p in manager.Products)
- {
- ASP.MasterDetailDropDown productMasterDetail;
- productMasterDetail = (ASP.MasterDetailDropDown)LoadControl("~/controls/MasterDetailDropDown.ascx");
- productMasterDetail.ID = p.name + " DropDown";
- productMasterDetail.product = p;
- productMasterDetail.ListBoxID = p.name + "-BuildNumberListBox";
- PlaceHolder.Controls.Add(productMasterDetail);
- }
the UserControl is set out like this -
Expand|Select|Wrap|Line Numbers
- <%@ Control ClassName="MasterDetailDropDown" Language="C#" AutoEventWireup="true"
- CodeFile="MasterDetailDropDown.ascx.cs" EnableTheming="true" Inherits="MasterDetailDropDown" %>
- <div class="ProductDataItem">
- <div class="ProductDataItemHeader">
- <h2>
- <asp:Label ID="mainMasterNameLabel" runat="server" Text="Label"></asp:Label></h2>
- <p>
- <asp:Label ID="subMasterNameLabel" runat="server" Text="Label"></asp:Label></p>
- <span class="showHideButton">
- <asp:ImageButton ID="ShowHideImageButton" runat="server" ImageUrl="~/Images/show.png"
- OnClick="ShowHideImageButton_Click" />
- </span>
- </div>
- <div class="ProductDataItemDetail">
- <asp:Panel ID="DetailPanel" runat="server" Visible="False">
- <div class="FloatListBoxLeft">
- <asp:ListBox ID="BuildNumberListBox" runat="server" SkinID="ListBox" AutoPostBack="true" OnSelectedIndexChanged="BuildNumberListBox_SelectedIndexChanged">
- </asp:ListBox>
- </div>
- <div class="BuildDetails">
- <ul>
- <li>Build:
- <asp:Label ID="BuildNumberLabel" runat="server" Text="Label"></asp:Label></li>
- <li>Build Successful:
- <asp:Image ID="BuildSuccessfulImage" runat="server" /></li>
- <li>Build Time/Date:
- <asp:Label ID="BuildTimeDateLabel" runat="server" Text="Label"></asp:Label></li>
- <li>Build Location:
- <asp:HyperLink ID="BuildLocationHyperlink" runat="server">HyperLink</asp:HyperLink></li>
- </ul>
- </div>
- <div class="BVTData">
- <ul>
- <li>Pass Rate(%) </li>
- <li>BVT Completion(%) </li>
- <li>Number of Critical Issues Rasied </li>
- <li>Number of Highs Issues Raised </li>
- <li>Number of Medium Issues Raised </li>
- <li>Number of Low Issues Raised </li>
- </ul>
- </div>
- </asp:Panel>
- </div>
- </div>
the code which bind the listbox goes like this -
Expand|Select|Wrap|Line Numbers
- mainMasterNameLabel.Text = product.name;
- subMasterNameLabel.Text = "v" + product.Version.ToString();
- //Builds ListBox
- foreach (Build b in this.product.builds)
- {
- ListItem buildListItem = new ListItem(b.BuildNumber.ToString(), b.Id.ToString());
- BuildNumberListBox.Items.Add(buildListItem);
- }
Thanks in advance.