ProductModel.cs
: (class)
public List<Product> GetSearchedProduct (string Name)
{
try
{
using (garagedbEntities db = new garagedbEntities())
{
List<Product> products = (from x in db.Products
where x.Name LIKE @txtSearch
select x).ToList();
return products;
}
}
catch (Exception)
{
return null;
}
}
search.aspx
:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<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>
<div style="clear:both"></div>
This is my search.aspx
file. Actually I want to get the name of the product
from TextBox
then pass it to method which retrieves the products
.