protected void Button1_Click(object sender, EventArgs e) { string searchTerm = txtSearchTerm.Text; using (NorthwindDataContext context = new NorthwindDataContext()) { string whereClause = "ProductName.Contains(\"" + searchTerm + "\")"; var q = context.Products.Where(whereClause); this.ProductGridView.DataSource = q; this.ProductGridView.DataBind(); this.ProductCount.Text = this.ProductGridView.Rows.Count.ToString("n0"); this.SearchPanel.Visible = true; } }
protected void Button1_Click(object sender, EventArgs e) { string searchTerm = txtSearchTerm.Text; using (NorthwindDataContext context = new NorthwindDataContext()) { var q = from p in context.Products where p.ProductName.Contains(searchTerm) select p; this.ProductGridView.DataSource = q; this.ProductGridView.DataBind(); this.ProductCount.Text = this.ProductGridView.Rows.Count.ToString("n0"); this.SearchPanel.Visible = true; } }