Tuesday, January 26, 2010

Bind the table with dropdown

tring strCategory1 = “select * from tbl_test where status=’Active’ and id=’” + drpmaincategory.SelectedValue.ToString() + “‘”;
SqlCommand cmdCategory1 = new SqlCommand(strCategory1, conn);
cmdCategory1.CommandType = CommandType.Text;
SqlDataAdapter daCategory1 = new SqlDataAdapter(cmdCategory1);
DataSet dsCategory1 = new DataSet();
daCategory1.Fill(dsCategory1, “tbl_test”);
drpsubcategory.DataSource = dsCategory1.Tables["tbl_test"];
drpsubcategory.DataTextField = “name”;
drpsubcategory.DataValueField = “id”;
drpsubcategory.DataBind();
drpsubcategory.Items.Insert(0, new ListItem(“Select SubCategory”, “”));