private void bindGrid() { Collection <CategoryCL> categories = categoryBLL.getAllCategories(); Collection <newCategoryCL> category = getCatName(categories); if (category.Count() > 0) { GvCategory.DataSource = category; GvCategory.DataBind(); } else { DataTable dt = new DataTable(); ShowNoResultFound(category, GvCategory); } }
protected void btnCatSearch_Click(object sender, EventArgs e) { Collection <CategoryCL> grd = categoryBLL.getAllCategories(); Collection <newCategoryCL> newGrd = getCatName(grd); var xyz = newGrd.Where(x => x.id >= 0); if (txtDesc.Text == string.Empty && txtFeature1.Text == string.Empty && txtFeature2.Text == string.Empty && txtFeature3.Text == string.Empty && txtFeature4.Text == string.Empty && txtName.Text == string.Empty && txtParentCategory.Text == string.Empty) { if (newGrd.Count > 0) { GvCategory.DataSource = newGrd; GvCategory.DataBind(); } else { DataTable dt = new DataTable(); ShowNoResultFound(newGrd, GvCategory); } } else { if (txtName.Text != string.Empty) { xyz = xyz.Where(x => x.categoryName.ToLower().Contains(txtName.Text.ToLower())); } if (txtParentCategory.Text != string.Empty) { xyz = from x in xyz where x.parentCategory == txtParentCategory.Text select x; } if (txtFeature1.Text != string.Empty) { xyz = from x in xyz where x.feature1.ToLower() == txtFeature1.Text.ToLower() select x; } if (txtFeature2.Text != string.Empty) { xyz = from x in xyz where x.feature2.ToLower() == txtFeature2.Text.ToLower() select x; } if (txtFeature3.Text != string.Empty) { xyz = from x in xyz where x.feature3.ToLower() == txtFeature3.Text.ToLower() select x; } if (txtFeature4.Text != string.Empty) { xyz = from x in xyz where x.feature4.ToLower() == txtFeature4.Text.ToLower() select x; } if (txtDesc.Text != string.Empty) { xyz = from x in xyz where x.description.ToLower().Contains(txtDesc.Text.ToLower()) select x; } Collection <newCategoryCL> xyzUpdate = new Collection <newCategoryCL>(); foreach (var item in xyz) { xyzUpdate.Add(new newCategoryCL() { id = item.id, dateModified = item.dateModified, dateCreated = item.dateCreated, isDeleted = item.isDeleted, categoryName = item.categoryName, description = item.description, feature1 = item.feature1, feature2 = item.feature2, feature3 = item.feature3, feature4 = item.feature4, parentCategory = item.parentCategory }); } if (xyzUpdate.Count() > 0) { GvCategory.DataSource = xyzUpdate; GvCategory.DataBind(); } else { DataTable dt = new DataTable(); ShowNoResultFound(xyzUpdate, GvCategory); } } }