Milas
Milas

Reputation: 347

listview databinding problem

i binding a dataset with a listview i want to i have a category table with have the following column (id,catName,CatPic) im looping in the database to get all record in the category table and place the data in a dataSet.

then i want bind the dataset to a list view display Categoy Picture and write the Category name underneath the picture

dataset holding all category record:

Dim CategoryDataSet As New DataSet
CatList.DataSource = CategoryDataSet 
CatList.DataBind()

 <asp:ListView ID="productslist" runat="server">
        <LayoutTemplate >
        <ul class ="productlist">
        <asp:PlaceHolder id="itemPlaceholder" runat="server" />
        </ul>
        </LayoutTemplate>

        <ItemTemplate>
        <li><asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# Eval("id", "picManu/Handler.ashx?ID={0}")%>' />
        <br/><%Eval("catName")%></li>  
        </ItemTemplate>

         <EmptyDataTemplate>
         <div>
         sorry no categoryfound
         </div>
         </EmptyDataTemplate>

    </asp:ListView>

problem:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

what i am doing wrong?

Upvotes: 0

Views: 593

Answers (2)

gsharp
gsharp

Reputation: 27937

You can not bind the DataSet itself, you have to bind the DataTable inside the DataSet.

Upvotes: 0

Oded
Oded

Reputation: 499392

You are not using the correct syntax for data binding expressions.

Instead of:

<br/><%Eval("catName")%></li>

Use:

<br/><%#Eval("catName")%></li>

Upvotes: 1

Related Questions