I am working on an online shopping project.......
I want to retrive data from database using checkbox......
For Example....
i have an mobbile form..... having all mobile records and have some filters such as search by brand, search by range etc....
let me take example of search by brand ......
In search by brand have 4 checkbox named Nokia(Checkbox1), Samsung(Checkbox2), Sony Erricson(Checkbox3) and Blackberry(Checkbox4).... such that if user selects Nokia all nokia mobiles will be shown to him... now problem is that if user selects two checkboxes such as nokia and samsung.... he cant see both he can see only one brands mobile either nokia or samsung.... please help...... mY code as follows..... Checkbox auto post back property set to true....
public partial class Mobiles : System.Web.UI.Page
{
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=HP-HP;Initial Catalog=OnlineShop;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand("Select Product_Code, Name,Brand,Price,Image from mobiles", con);
SqlDataReader dr = cmd.ExecuteReader();
dt = new DataTable();
dt.Load(dr);
DataList1.DataSourceID = null;
DataList1.DataSource = dt;
DataList1.DataBind();
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked == true)
{
DataView dv = dt.DefaultView;
dv.RowFilter = "Brand='Nokia'";
DataList1.DataSource = dv;
DataList1.DataBind();
}
}
protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox4.Checked == true)
{
DataView dv = dt.DefaultView;
dv.RowFilter = "Brand='Blackberry'";
DataList1.DataSource = dv;
DataList1.DataBind();
}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox2.Checked == true)
{
DataView dv = dt.DefaultView;
dv.RowFilter = "Brand='Sony Ericson'";
DataList1.DataSource = dv;
DataList1.DataBind();
}
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox3.Checked == true)
{
DataView dv = dt.DefaultView;
dv.RowFilter = "Brand='Samsung'";
DataList1.DataSource = dv;
DataList1.DataBind();
}
}
}