I am trying to view my products in list view dynamically and this is my try

    <asp:ListView ID="mylistView" runat="server" GroupItemCount="3" 

            onitemdatabound="mylistView_ItemDataBound" 
            onitemcreated="mylistView_ItemCreated">
            <GroupTemplate>
                <tr id="itemPlaceholderContainer" runat="server">
                    <td id="itemPlaceholder" runat="server">
                    </td>
                </tr>
            </GroupTemplate>
            <LayoutTemplate>
                <asp:Label ID="lab" runat="server" Text='<%#Eval("MenuName") %>'></asp:Label>
                <asp:Image ID="foo" ImageUrl='<%#Eval("MenuName") %>' runat="server" />
                <table id="Table1" runat="server">
                    <tr id="Tr1" runat="server">
                        <td id="Td1" runat="server">
                            <table id="groupPlaceholderContainer" runat="server">
                                <tr id="groupPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr id="Tr2" runat="server">
                        <td id="Td2" runat="server">
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <table border="0" width="300" style="display: inline-block; background-color: Lime;">
                    <tr>
                        <td>
                            &nbsp
                        </td>

                        <td>
                            <a><b style="text-decoration: underline;">
                                <%# Eval("mainItem") %></b> </a>
                            <br />

                        <asp:Repeater ID="rep" runat="server">
                            <HeaderTemplate>

                            </HeaderTemplate>
                            <ItemTemplate>
                            <li>
                                  <%#((ProductsItems)Container.DataItem).subItems%>
                            </li>

                            </ItemTemplate>
                            <FooterTemplate>

                            </FooterTemplate>
                      </asp:Repeater> 


                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:ListView>
        <asp:SqlDataSource ID="dataSource" runat="server"></asp:SqlDataSource>

in code behind

     public void databind()
{
    string prod1 = "P1";
    string prod2 = "P2";
    string prod3 = "P3";
    List<string> list1 = new List<string>();
    list1.Add("P11");
    list1.Add("P12");
    list1.Add("P13");

    List<string> list2 = new List<string>();
    list1.Add("P21");
    list1.Add("P22");
    list1.Add("P23");

    List<string> list3 = new List<string>();
    list1.Add("P31");
    list1.Add("P32");
    list1.Add("P33");

     List<ProductsItems> listprodItems = new List<ProductsItems>
 {
 new ProductsItems(){ mainItem = prod1, subItems=list1 },
 new ProductsItems(){ mainItem = prod2, subItems=list2 },
  new ProductsItems(){ mainItem = prod3, subItems=list3 }
 };
    mylistView.DataSource = listprodItems;
    mylistView.DataBind();

 }

this is my prduct object

public class ProductsItems
{
public string mainItem { get; set; }
public List<string> subItems { get; set; }
}

how can i show the title for every product and its subItems using repeater under every one? many thanks for help.

Related posts

Recent Viewed