protected void SubcategoryList_SelectedIndexChanged(object sender, EventArgs e) { String catid = CategoryList.SelectedValue.ToString(); String subcatid = SubcategoryList.SelectedValue.ToString(); //Response.Write(catid); //Response.Write(subcatid); conn = new MySqlConnection(GetConnectionString()); Specification1.Visible = false; SpecificationRList1.Visible = false; Specification2.Visible = false; SpecificationRList2.Visible = false; Specification3.Visible = false; SpecificationRList3.Visible = false; Specification4.Visible = false; SpecificationRList4.Visible = false; Specification5.Visible = false; SpecificationRList5.Visible = false; Specification6.Visible = false; SpecificationRList6.Visible = false; Specification7.Visible = false; SpecificationRList7.Visible = false; try { conn.Open(); String query1 = "Select Product_ID,CONCAT(Company_Name,' ',Product_Name,' ',Sp4_Value,' ',Sp5_Value,' ',Sp6_Value,' ',Sp7_Value,' ',Sp8_Value,' MRP ',Retail_Price,' WP ',Wholesale_Price,' Stock ',Stock) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlCommand comm = new MySqlCommand(query1, conn); MySqlDataReader dr1 = comm.ExecuteReader(); //ProductsList.ClearSelection(); ProductsList.DataSource = dr1; ProductsList.DataTextField = "CONCAT(Company_Name,' ',Product_Name,' ',Sp4_Value,' ',Sp5_Value,' ',Sp6_Value,' ',Sp7_Value,' ',Sp8_Value,' MRP ',Retail_Price,' WP ',Wholesale_Price,' Stock ',Stock)"; ProductsList.DataValueField = "Product_ID"; ProductsList.DataBind(); dr1.Close(); comm.CommandText = "Select DISTINCT(Company_Name) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlDataReader dr2 = comm.ExecuteReader(); BrandList.DataSource = dr2; BrandList.DataTextField = "Company_Name"; BrandList.DataValueField = "Company_Name"; BrandList.DataBind(); dr2.Close(); BrandList.Visible = true; Label4.Visible = true; comm.CommandText = "Select Specification4,Specification5,Specification6,Specification7,Specification8,Specification9,Specification10 from Specifications where Category_ID='" + catid + "' and Subcategory_ID = '" + subcatid + "'"; MySqlDataReader dr3 = comm.ExecuteReader(); String[] Specs = new String[7]; dr3.Read(); for (int i = 0; i < 7; i++) { Specs[i] = dr3.GetValue(i).ToString(); } dr3.Close(); if (Specs[0] != "") { Specification1.Text = Specs[0]; Specification1.Visible = true; } if (Specs[1] != "") { Specification2.Text = Specs[1]; Specification2.Visible = true; } if (Specs[2] != "") { Specification3.Text = Specs[2]; Specification3.Visible = true; } if (Specs[3] != "") { Specification4.Text = Specs[3]; Specification4.Visible = true; } if (Specs[4] != "") { Specification5.Text = Specs[4]; Specification5.Visible = true; } if (Specs[5] != "") { Specification6.Text = Specs[5]; Specification6.Visible = true; } if (Specs[6] != "") { Specification7.Text = Specs[6]; Specification7.Visible = true; } if (Specification1.Visible) { comm.CommandText = "Select DISTINCT(Sp4_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlDataReader dr4 = comm.ExecuteReader(); SpecificationRList1.DataSource = dr4; SpecificationRList1.DataTextField = "Sp4_Value"; SpecificationRList1.DataValueField = "Sp4_Value"; SpecificationRList1.DataBind(); SpecificationRList1.Visible = true; dr4.Close(); } if (Specification2.Visible) { comm.CommandText = "Select DISTINCT(Sp5_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlDataReader dr4 = comm.ExecuteReader(); SpecificationRList2.DataSource = dr4; SpecificationRList2.DataTextField = "Sp5_Value"; SpecificationRList2.DataValueField = "Sp5_Value"; SpecificationRList2.DataBind(); SpecificationRList2.Visible = true; dr4.Close(); } if (Specification3.Visible) { comm.CommandText = "Select DISTINCT(Sp6_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlDataReader dr4 = comm.ExecuteReader(); SpecificationRList3.DataSource = dr4; SpecificationRList3.DataTextField = "Sp6_Value"; SpecificationRList3.DataValueField = "Sp6_Value"; SpecificationRList3.DataBind(); SpecificationRList3.Visible = true; dr4.Close(); } if (Specification4.Visible) { comm.CommandText = "Select DISTINCT(Sp7_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlDataReader dr4 = comm.ExecuteReader(); SpecificationRList4.DataSource = dr4; SpecificationRList4.DataTextField = "Sp7_Value"; SpecificationRList4.DataValueField = "Sp7_Value"; SpecificationRList4.DataBind(); SpecificationRList4.Visible = true; dr4.Close(); } if (Specification5.Visible) { comm.CommandText = "Select DISTINCT(Sp8_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlDataReader dr4 = comm.ExecuteReader(); SpecificationRList5.DataSource = dr4; SpecificationRList5.DataTextField = "Sp8_Value"; SpecificationRList5.DataValueField = "Sp8_Value"; SpecificationRList5.DataBind(); SpecificationRList5.Visible = true; dr4.Close(); } if (Specification6.Visible) { comm.CommandText = "Select DISTINCT(Sp9_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlDataReader dr4 = comm.ExecuteReader(); SpecificationRList6.DataSource = dr4; SpecificationRList6.DataTextField = "Sp9_Value"; SpecificationRList6.DataValueField = "Sp9_Value"; SpecificationRList6.DataBind(); SpecificationRList6.Visible = true; dr4.Close(); } if (Specification7.Visible) { comm.CommandText = "Select DISTINCT(Sp10_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'"; MySqlDataReader dr4 = comm.ExecuteReader(); SpecificationRList7.DataSource = dr4; SpecificationRList7.DataTextField = "Sp10_Value"; SpecificationRList7.DataValueField = "Sp10_Value"; SpecificationRList7.DataBind(); SpecificationRList7.Visible = true; dr4.Close(); } } catch (Exception ex) { Response.Write(ex.Message); } finally{ conn.Close(); } BrandList.Items.Insert(0, new ListItem("", "0")); }