Shiva Tiwari

Shiva Tiwari

  • NA
  • 73
  • 5.2k

filter records with multiple checkbox

Aug 4 2020 4:33 AM
public void PopulateProductBrand()
{
try
{
string query = "SELECT * FROM ProductBrand";
SqlCommand cmd = new SqlCommand(query, ConMangalya);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
strBrand += @"<div class='custom-control custom-checkbox collection-filter-checkbox'>
<input type='checkbox' name='brand' class='custom-control-input GetP' id='" + dr["ProductBrand"] + @"' onClick='SearchBrand(this.id);'>
<label class='custom-control-label' for='" + dr["ProductBrand"] + @"'>" + dr["ProductBrand"] + @"</label>
</div>";
}
}
}
catch (Exception ex)
{
}
}
public void PopulateProductSize()
{
try
{
string query = "SELECT * FROM ProductSize";
SqlCommand cmd = new SqlCommand(query, ConMangalya);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
strSize += @"<div class='custom-control custom-checkbox collection-filter-checkbox'>
<input type='checkbox' name='size' class='custom-control-input GetP' id='" + dr["Size"] + @"'>
<label class='custom-control-label' for='" + dr["Size"] + @"'>" + dr["Size"] + @"</label>
</div>";
}
}
}
catch (Exception ex)
{
}
}
public void PopulateProductColor()
{
try
{
string query = "SELECT * FROM ProductColor";
SqlCommand cmd = new SqlCommand(query, ConMangalya);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
strColor += @"<li style='background-color:"+ dr["color"] + @"' id='"+dr["color"] + @"' class='GetC'></li>";
}
}
}
catch (Exception ex)
{
}
}
public void PopulatePriceRange()
{
try
{
string query = "SELECT * FROM ProductPrice";
SqlCommand cmd = new SqlCommand(query, ConMangalya);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
strPrice += @"<div class='custom-control custom-checkbox collection-filter-checkbox'>
<input type='checkbox' name='price' class='custom-control-input GetP' id='" + dr["Price"] + @"'>
<label class='custom-control-label' for='" + dr["Price"] + @"'>" + dr["Price"] + @"</label>
</div>";
}
}
}
catch (Exception ex)
{
}
}
[WebMethod]
public static string PopulateProducts(string Data)
{
SqlConnection ConMangalya = new SqlConnection(ConfigurationManager.ConnectionStrings["ConMangalya"].ConnectionString);
string products = "";
string c = "";
string Sc = "";
string sh = "";
try
{
string query = "Select * from AddProduct Where SubCatUrl=@SubCatUrl OR ProductBrand=@ProductBrand OR Color=@Color OR Size=@Size OR PriceRange=@PriceRange";
SqlCommand cmd = new SqlCommand(query, ConMangalya);
cmd.Parameters.AddWithValue("@SubCatUrl", SqlDbType.VarChar).Value = Data;
cmd.Parameters.AddWithValue("@ProductBrand", SqlDbType.VarChar).Value = Data;
cmd.Parameters.AddWithValue("@Color", SqlDbType.VarChar).Value = Data;
cmd.Parameters.AddWithValue("@Size", SqlDbType.VarChar).Value = Data;
cmd.Parameters.AddWithValue("@PriceRange", SqlDbType.VarChar).Value = Data;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
c= dr["Category"].ToString();
sh= dr["Shop"].ToString(); ;
Sc= dr["SubCat"].ToString();
string strImg = dr["SmallImage"].ToString();
string[] strImg_arr = strImg.Split(',');
string strRating = "";
int rating = Convert.ToInt32(dr["ProductRating"]);
for (int i = 1; i <= rating; i++)
{
strRating += @"<i class='fa fa-star'></i>";
}
products += @"<div class='col-xl-3 col-6 col-grid-box'>
<div class='product-box'>
<div class='img-wrapper'>
<div class='front'>
<a href='#'><img src='/" + strImg_arr[0] + @"' class='img-fluid blur-up lazyload bg-img' alt=''></a>
</div>
<div class='back'>
<a href='#'><img src='/" + strImg_arr[1] + @"' class='img-fluid blur-up lazyload bg-img' alt=''></a>
</div>
<div class='cart-info cart-wrap'>
<button data-toggle='modal' data-target='#addtocart' title='Add to cart'><i
class='ti-shopping-cart'></i></button> <a href = 'javascript:void(0)' title='Add to Wishlist'><i
class='ti-heart' aria-hidden='true'></i></a> <a href='#' data-toggle='modal' data-target='#quick-view' title='Quick View'><i
class='ti-search' aria-hidden='true'></i></a> <a href='compare.html' title='Compare'><i
class='ti-reload' aria-hidden='true'></i></a>
</div>
</div>
<div class='product-detail'>
<div>
<div class='rating'>" + strRating + @"</div>
<a href='product-page(no-sidebar).html' >
<h6>" + dr["ProductName"] + @"</h6>
</a>
<h4>" + dr["SellingPrice"] + @"</h4>
<ul class='color-variant'>
<li class='bg-light0'></li>
<li class='bg-light1'></li>
<li class='bg-light2'></li>
</ul>
</div>
</div>
</div>
</div>";
}
}
}
catch (Exception ex)
{
}
return products + ',' + c + ',' + sh + ',' + Sc;
}

Answers (1)