I have a page with two DropDownList. One of them populating the list in Page_Load () with information retrieved from a database.
What I wish is that I select an item in DropDownList min can use what's in it in an SQL query for populating the second box.
Code:
protected void Page_Load (object sender, EventArgs e)
{
dbConn = tcObj.returnConnection ();
try
{
dbConn.Open ();
}
catch (Exception connectionException) ()
populateClientDropdown ();
}
Code:
private void populateClientDropdown ()
{
clientDownList.Items.Clear ();
executeReader ( "SELECT Company FROM Client");
dropDownElements.Clear ();
while (dbReader.Read ())
{
dropDownElements.Add (dbReader [ "Company"]. ToString ());
}
dbReader.Close ();
for (int i = 0; i <dropDownElements.Count; i + +)
{
Listitem lstItem = new Listitem (Drop Down Elements [i]. ToString ());
clientDownList.Items.Add (lstItem);
}
}
Code:
private void populateSubClientDropdown ()
{
subClientDropDownList.Items.Clear ();
executeReader ( "SELECT Client_Location.Sub_Company_Name FROM Client_Location, Client WHERE Client_Location.Client_ID = Client.ID_Client AND Client.Company = '" + clientDownList.Text +"'");
dropDownElements.Clear ();
while (dbReader.Read ())
{
dropDownElements.Add (dbReader [ "Sub_Company_Name"]. ToString ());
}
for (int i = 0; i <dropDownElements.Count; i + +)
{
Listitem lstItem = new Listitem (Drop Down Elements [i]. ToString ());
subClientDropDownList.Items.Add (lstItem);
}
}
Code:
protected void clientDownList_SelectedIndexChanged (object sender, EventArgs e)
{
populateSubClientDropdown ();
}
Code:
<asp: DropDownList ID = "client Down List" runat = "server" Auto Post Back = "True"
onselectedindexchanged = "clientDownList_SelectedIndexChanged">
</asp: DropDownList>
It's happening now is that the Page_Load () is run every time I change the item in the DropDownList min, resulting in the error value is used when using clientDownList.Text in my query.
Bookmarks