473,394 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Dropdownlist depending another Dropdownlist

3
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();
}


}
May 17 '07 #1
0 730

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jonathan | last post by:
Hi everyone, i have made two dropdownlist controls. On my first one, i have the country and on the second one, the state (for example) if i selected the United States country. So depending on wich...
7
by: Piotr Strycharz | last post by:
Hi all. I have problem with ASP:DropDownList. I do not know how to get its value. The DropDownList is populated in Page_Load method (from SQL Server). When this list is embeded in ASPX page...
4
by: Yahya Saad | last post by:
Dear All, I have an ASP.Net webform that includes a DropDownList (bound to a dataview including 6000 records) and a textbox that is updated according to the selection of an event at the...
2
by: Jennyfer J Barco | last post by:
Hello is there a way to create a dropdownlist inside a <input type='dropdownlist'> or there is an equivalent to create other than <asp:DropDownList id="drop1" runat="server"> . I need this because...
3
by: Olivier Verdin | last post by:
Hi, I have a page with several Textboxes and several DropDownList. When I click on a 'save' button, it creates a record in a database. The page works fine under Internet Explorer. It does...
0
by: Tand35006 | last post by:
Hi, I hope some one can help with this. I have a basic webform with 2 DropDownLists and a single DataGrid. What I am trying to do is populate the first DDList from a dataset on Form_Load. I then...
0
by: brian.newman | last post by:
I've created a dropdownlist whose values are drawn from an Access database. This list of items represents a user account. In the same record is a boolean field which records whether the user is...
3
by: =?Utf-8?B?RGVlcGE=?= | last post by:
Hi All, I have a webform in asp.net framework 1.1 where the dropdownlist is populated with list of locations from the database. The depending on the list selected, the user will be able to see...
5
by: =?Utf-8?B?Q2hyaXMgRy4=?= | last post by:
I'm trying to put conditional code in a dropdown that would check the value of the current ListItem and set Selected=true depending on that value, and Selected=false if it's any other value. Due...
11
by: harold.gimenez | last post by:
Hi group, I am trying to change the selection of an ASP Dropdownlist just like "Orange" is selected here: http://www.w3schools.com/js/tryit.asp?filename=try_dom_option_selected The...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.