protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { populatemobile(); } } public DataSet getdata(string sqlquery) { SqlConnection con = new SqlConnection(@"server=DELL\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=product;"); SqlDataAdapter da = new SqlDataAdapter(sqlquery, con); DataSet ds = new DataSet(); da.Fill(ds); return ds; } public void populatemobile() { DataSet ds = getdata("Select * from ITEM_TYPE"); MOBDropDownList.DataSource = ds; MOBDropDownList.DataValueField = "TYPE_ID"; MOBDropDownList.DataTextField = "MOBILE_NAME"; MOBDropDownList.DataBind(); NAMEDropDownList.Enabled = false; ListItem limob = new ListItem("Select MOBILE_NAME", "-1"); MOBDropDownList.Items.Insert(0, limob); ListItem liname = new ListItem("Select MOBILE_TYPE", "-1"); NAMEDropDownList.Items.Insert(0, liname); } protected void MOBDropDownList_SelectedIndexChanged(object sender, EventArgs e) { if (MOBDropDownList.SelectedValue == "-1") { NAMEDropDownList.SelectedIndex = 0; NAMEDropDownList.Enabled = false; } else { NAMEDropDownList.Enabled = true; NAMEDropDownList.DataSource = getdata("Select * from ITEMS where MOBILE_ID = '" + MOBDropDownList.SelectedValue.ToString() + "'"); NAMEDropDownList.DataTextField = "MOBILE_MODEL"; NAMEDropDownList.DataValueField = "TYPE_ID"; NAMEDropDownList.DataBind(); ListItem liname = new ListItem("Select MOBILE_TYPE", "-1"); NAMEDropDownList.Items.Insert(0, liname); } if (NAMEDropDownList.Enabled == true) { string str = @"server=DELL\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=product;"; SqlConnection con = new SqlConnection(str); try { con.Open(); string query = "select * from ITEMS where TYPE_ID= '" + MOBDropDownList.Text + "' "; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader dbr; dbr = cmd.ExecuteReader(); while (dbr.Read()) { string price = dbr.GetInt32(1).ToString(); pricetxtbox.Text = price; } con.Close(); } catch (Exception er) { MessageBox.Show(er.Message); } } else { string str = @"server=DELL\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=product;"; SqlConnection con = new SqlConnection(str); try { con.Open(); string query = "select * from ITEMS where MOBILE_PRICE= '" + MOBDropDownList.Text + "' "; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader dbr; dbr = cmd.ExecuteReader(); while (dbr.Read()) { string price = dbr.GetInt32(1).ToString(); pricetxtbox.Text = price; } con.Close(); } catch (Exception er) { MessageBox.Show(er.Message); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)