<asp:ListView ID="ListView1" runat="server" ondatabound="ListView1_DataBound"
onitemdatabound="ListView1_ItemDataBound" >
<LayoutTemplate>
<ul class="productlist">
<asp:PlaceHolder ID="itemPlaceholder" runat="server">asp:PlaceHolder>
ul>
LayoutTemplate>
<ItemTemplate>
<li><img src='Images/ART MATERIALS/<%#Eval("ImageURL") %>' /><br />
<asp:LinkButton ID="HyperLink1" runat="server" Text='<%#Eval("Name")%>' PostBackUrl='<%#Eval("WebSite")%>'/>
<asp:HiddenField id="hdnProductId" runat="server"/>
li>
ItemTemplate>
<EmptyDataTemplate>
<div style="text-align:center;">No Products founddiv>
EmptyDataTemplate>
asp:ListView>
internal sealed class Products
{
//public int ID { get; set; }
public string Name { get; set; }
public string ImageUrl { get; set; }
public string WebSite { get; set; }
}
DataSet dsProduct = new DataSet();
string strQry = "Select * from ProductDet where ProductId in(select ProductId from ProductMaster where CatId = '1' and SubCatId='" + intSubCatId + "' and BrandId='" + intBrandId + "')";
dsProduct = db.GetTableDefinedDataSet(strQry, "Products");
if (dsProduct.Tables["Products"].Rows.Count > 0)
{
var query = dsProduct.Tables["Products"].AsEnumerable()
.GroupBy(x => x.Field<string>("ProductName").ToString())
.Select(x => x.First());
foreach (DataRow DistinctProducts in query)
{
// drpAvailableColours.Items.Add(new ListItem(DistinctProducts["ProductName"].ToString(), DistinctProducts["ColourCode"].ToString()));
new Products { Name = DistinctProducts["ProductName"].ToString(), ImageUrl = "~/Images/ART MATERIALS/" + DistinctProducts["ImageURL"].ToString(), WebSite = "temp.aspx?CatId=1&SubCatId=" + intSubCatId + "&BrandId=" + intBrandId };
}
ListView1.DataSource = ProdList;
ListView1.DataBind();
Deepa SudhirPosted Mar 7, 2015, 4:17 AM
There is no date in my code
I have a listview control with image and image name & a link button and to needs to add values to these controls programmatically using a dataset
I have taken the values of the dataset in a list called products and filled the controls on the listview
but it always shows no data even though there are records
Please check if I have gone some where wrong in binding the listview to the list "product"
Manish Kumar ChoudharyPosted Mar 7, 2015, 4:01 AM
Deepa SudhirPosted Mar 7, 2015, 3:58 AM