If you want to display data based on DropDownList selection, means if you want to implement cascading then you have to implement code in SelectedIndexChanged() Event of DropDownList.
I m giving sample code for that-
1. here i m filling DropDownList1 with category
//for binding DropDownList1 with category
private void DataGrid_Load(object sender, EventArgs e)
{
getdata();
}
//function for getting category
private void getdata()
{
SqlConnection cn = new SqlConnection("constring");
cn.Open();
string strQuery = "Select categoryid,categoryname from category ";
SqlDataAdapter da = new SqlDataAdapter(strQuery, cn);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DisplayMember = "categoryid";
DropDownList1.ValueMember = "categoryname ";
DropDownList1.DataSource = ds.Tables[0];
}
2. here i m filling DropDownList2 with product , based on selection on DropDownList1
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("constring");
cn.Open();
string strQuery = "Select productid,productname from producttab where categoryid='" + DropDownList1.SelectedValue .ToString() + "'";
SqlDataAdapter da = new SqlDataAdapter(strQuery, cn);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList2 .DisplayMember = "productid";
DropDownList2.ValueMember = "productname ";
DropDownList2.DataSource = ds.Tables[0];
}
3. here i m filling DropDownList3 with product-price, based on selection on DropDownList2
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("constring");
cn.Open();
string strQuery = "Select product-price from product-pricetab where categoryid='" + DropDownList1.SelectedValue .ToString() + "' and productid='" + DropDownList2.SelectedValue .ToString() + "' ";
SqlDataAdapter da = new SqlDataAdapter(strQuery, cn);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList3.DisplayMember = "product-price";
DropDownList3.ValueMember = "product-price";
DropDownList3.DataSource = ds.Tables[0];
}
USE THIS CODE AND LET ME KNOW.