开发者

Dual listview binding help

I have a listview of buttons(I wanted to have hyperlinks actually but have no idea how to execute without the onclick event) where I can click and show the sub categories products of a master category on another listview(already binded with products of master category table). This is my code below, apparently it does not work as expected and throws the error below:

"Both DataSource and DataSourceID are defined on 'ListView_Products'. Remove one definition."

Can someone please advice how to deal with this? Thanks.

Here is a "picture" of what I am trying to do:

**ListView 1(Sub Category)**             **ListView 2(Master Category)**
         Cotton                                "ALL THE DRESSES"
         Silk                                           

So when I click cotton in ListView1, only dresses made of Cotton will be displayed on ListView2.

<asp:ListView ID="ListView_ProductsMenu" runat="server" 
 开发者_如何转开发           DataKeyNames="CategoryID" DataSourceID="EDS_Category_Menu" >
            <EmptyDataTemplate>No Menu Items.</EmptyDataTemplate>
            <ItemSeparatorTemplate></ItemSeparatorTemplate>
            <ItemTemplate>

                <li style="color: #B6B6B6; text-align: left; font-family: candara; font-size: small;" class="SideMenu">


                 <asp:Button ID="Button1" runat="server" Text='<%# Eval("Category_Sub_Name")%>' OnClick='<%# FormattedCategory((int)Eval("CategoryID"),(int)Eval("Category_Sub_ID")) %>'  /> 

                </li>
            </ItemTemplate>               

            <LayoutTemplate>
                <ul ID="itemPlaceholderContainer" runat="server" style="font-family: Verdana, Arial, Helvetica, sans-serif;">
                    <li runat="server" id="itemPlaceholder" />
                </ul>
                <div style="text-align: left;background-color: #FFCC66;font-family: Verdana, Arial, Helvetica, sans-serif;color: #333333;"></div>
            </LayoutTemplate>
        </asp:ListView>

Code behind:

 protected string FormattedCategory(int cID, int subCatID)
    {
        using (CommerceEntities db = new CommerceEntities())
        {
            ListView_Products.DataSource = null;
            ListView_Products.DataSource = (from c in db.Categories_Sub
                                            where c.CategoryID == cID
                             & c.Category_Sub_ID == subCatID
                          select c);         
            ListView_Products.DataBind();
            //foreach (var item in subCat)
            //{
            //     ListView_ProductsMenu.DataBind();
            // }
        }
        return null;
    }


Try to remove that attribute from <asp:ListView ... DataSourceID="EDS_Category_Menu"


Nevermind, it's ListView_Products.DataSourceID = null; actually. Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜