hello all!
i really need a help of a friend...
i am working on a self project.
and i am realy lost here...
i have to Dropdown list ,the first one gives me the name of the hospital
and the other one give me the name of the doctors that are in the same hospital.
iam using SP and they really work i tested them
but i have a problem with the doctors dropdownlist...
if i choose a doctor...and after i chose another doctor i see them both...
it always remembers the last doctor and keep remembering them all
PLEASE could some one help me code that.....
here is my code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillHospitalCombo();
}
FillDoctorCombo();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
//Got my id from Dropdownlist
zmn.Doctor_ID =Convert.ToInt32( DropDownList2.SelectedValue);
DropDownList2.Items.Clear();
string date;
//Get This format of date dd,mm,yy
date = DateTime.Today.Day.ToString();
date += "/" + DateTime.Today.Month.ToString();
date += "/" + DateTime.Today.Year.ToString();
zmn.Date = date;
#region My Old Way-->Now it"s just remarks
/*
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(StrCon);
//Execute GetHoleByDate Procedure
SqlCommand cmd = new SqlCommand("GiveDateFrom", con);
//telling him that we use SP
cmd.CommandType = CommandType.StoredProcedure;
//Create Parameter
SqlParameter MyParmeter = new SqlParameter();
//Scan Parameter Name,Type,Value
MyParmeter.ParameterName = "@ID";
MyParmeter.SqlDbType = SqlDbType.Int;
MyParmeter.Value = Doc.Doc_ID;
//AddParameter to cmd
cmd.Parameters.Add(MyParmeter);
SqlParameter MyParmeter2 = new SqlParameter();
MyParmeter2.ParameterName = "@Date";
MyParmeter2.SqlDbType = SqlDbType.NVarChar;
MyParmeter2.Value =zmn.Date;
//AddParameter to cmd
cmd.Parameters.Add(MyParmeter2);
SqlDataAdapter da = new SqlDataAdapter(cmd);
//Fill DT
con.Open();
da.Fill(dt);
con.Close();
*/
#endregion
DataTable dt = new DataTable();
dt = zmn.GetDateFromTodayAndOn();
//Show Grid
GridView1.DataSource = dt;
GridView1.RowStyle.HorizontalAlign = HorizontalAlign.Center;
GridView1.DataBind();
}
public void FillHospitalCombo()
{
SqlConnection conn = new SqlConnection(StrCon);
SqlCommand cmd = new SqlCommand("GetAllHospital", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader dr;
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList1.Items.Add(new ListItem(dr["Hospital_Name"].ToString(), dr["Hospital_ID"].ToString()));
}
conn.Close();
}
public void FillDoctorCombo()
{
string strsql = @"SELECT Doctors.Doctor_ID, Doctors.First_Name
FROM Doctors INNER JOIN
Hospital ON Doctors.Hospital_ID = Hospital.Hospital_ID
WHERE Hospital.Hospital_ID = {0}";
strsql = string.Format(strsql, DropDownList1.SelectedIndex.ToString());
SqlConnection conn = new SqlConnection(StrCon);
SqlCommand cmd = new SqlCommand(strsql, conn);
SqlDataReader dr;
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList2.Items.Add(new ListItem(dr["First_Name"].ToString(), dr["Doctor_ID"].ToString()));
}
conn.Close();
}
}