-
Notifications
You must be signed in to change notification settings - Fork 9
/
search.aspx.cs
44 lines (37 loc) · 1.62 KB
/
search.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eCommerceDBModel;
public partial class search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Get the lookup string form URL
string lookup = Request.QueryString["product"];
string category = Request.QueryString["category"];
Page.Title = "Search: " + lookup;
//Keeping the lookup string in searchbar for ease of use
((TextBox)this.Page.Master.FindControl("txtSearch")).Text = lookup;
using (eCommerceDBEntities context = new eCommerceDBEntities())
{
//Running %like query on 2 fields to get best results from DB
List<Product> pr = context.Products.Where(i => i.ProductName.Contains(lookup) ||
i.ProductDescription.Contains(lookup)
).ToList();
var lq = (from p in context.Products
join c in context.Categories
on p.CategoryID equals c.CategoryID
where (string.IsNullOrEmpty(category) ? true : c.CategoryName == category) &&
(string.IsNullOrEmpty(lookup)? true : p.ProductName.Contains(lookup) || p.ProductDescription.Contains(lookup))
select p).ToList();
Repeater1.DataSource = lq;
Repeater1.DataBind();
}
}
}
}