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 CategoryDat开发者_JS百科aSet 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?
You are not using the correct syntax for data binding expressions.
Instead of:
<br/><%Eval("catName")%></li>
Use:
<br/><%#Eval("catName")%></li>
You can not bind the DataSet
itself, you have to bind the DataTable
inside the DataSet
.
精彩评论