protected void SpecializationList_SelectedIndexChanged(object sender, EventArgs e) { try { DropDownList s = sender as DropDownList; string specialization = s.SelectedValue; string sqlConnString = ConfigurationManager.ConnectionStrings["ConnString"].ToString(); SqlConnection sqlConn = new SqlConnection(sqlConnString); sqlConn.Open(); String sql = "select s.specialist_name, s.specialist_id, sp.specialization_name, sp.specialization_id from specialist s, specialization sp where s.specialization_id = sp.specialization_id and sp.specialization_id ='" + specialization + " 'order by specialist_name"; SqlCommand sqlCmd = new SqlCommand(sql, sqlConn); SqlDataAdapter da = new SqlDataAdapter(sqlCmd); DataSet ds = new DataSet(); da.Fill(ds); SpecialistList.DataTextField = ds.Tables[0].Columns["specialist_name"].ToString(); SpecialistList.DataValueField = ds.Tables[0].Columns["specialist_id"].ToString(); SpecialistList.DataSource = ds.Tables[0]; SpecialistList.DataBind(); sqlConn.Close(); } catch (Exception ex) { Response.Write("Error:" + ex.ToString()); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { string sqlConnString = ConfigurationManager.ConnectionStrings["ConnString"].ToString(); SqlConnection sqlConn = new SqlConnection(sqlConnString); sqlConn.Open(); SqlCommand sqlCmd = new SqlCommand("select * from specialist order by 2", sqlConn); SqlDataAdapter da = new SqlDataAdapter(sqlCmd); DataSet ds = new DataSet(); da.Fill(ds); SpecialistList.DataTextField = ds.Tables[0].Columns["specialist_name"].ToString(); SpecialistList.DataValueField = ds.Tables[0].Columns["specialist_id"].ToString(); SpecialistList.DataSource = ds.Tables[0]; SpecialistList.DataBind(); //LocationList.SelectedIndex = 1; } catch (Exception ex) { Response.Write("Error:" + ex.ToString()); } } }