Deepa Sudhir

Deepa Sudhir

  • NA
  • 35
  • 21.1k

how to add data to itemtemplate controls in a list view

Mar 7 2015 3:56 AM

<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 found</div>

</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();






Answers (3)