c# - Creating a method for search product by name in "ProductModel" class and display it in panel with image buttons and labels -
productmodel.cs: (class)
this productmodel class searches product name. check if correct or not.
public static product searchproductsbyname(string name, list<product> products) { product pd; pd = new product(); foreach (product rs in products) { if (name == rs.name) { return pd; } } return null; // <<< return value if nothing found }
search.aspx:
<asp:textbox id="txtsearch" runat="server"></asp:textbox> <asp:button id="btnsearch" runat="server" text="button" onclick="btnsearch_click" /> <br /> <asp:panel id="pnlproducts" runat="server"> <br /> </asp:panel>
search.aspx.cs (i want display searched product using searched product ty name method)
protected void page_load(object sender, eventargs e) { } protected void btnsearch_click(object sender, eventargs e) { productmodel productmodel = new productmodel(); list<product> products = productmodel.searchproductsbyname**(txtsearch.text);** //getting error here //make sure product exist in db if (products != null) { //create new panel image btn & 2 labels foreach (product product in products) { panel productpanel = new panel(); imagebutton imagebutton = new imagebutton(); label lblname = new label(); label lblprice = new label();
you assigning list<product> products
function not return list<product>
so logically supposed have function returns list this:
public static list<product> searchproductsbyname() { // work // return list<product> }
so thats 1 of problems. other searchproductsbyname
function takes 2 arguments , providing 1 =>
productmodel.searchproductsbyname**(txtsearch.text)
so missing there variable of type list<product>
defined in searchproductsbyname
function.
Comments
Post a Comment