Hello,
I need some help with my cascading dropdown boxes. Eveything works I just need to remove the duplicates from the States and Cities drop down box. Any idea how? I got it to work on the Country drop down but can't figure out the rest. Thanks.
private void FillCountry()
{
DataSet ds = (DataSet)Cache["InfoToFilter"];
DataTable dt = new DataTable();
ds = GetInfoFromDB2();
dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
dr["country"] = AsciiToString(dr["country"].ToString());
}
dt.AcceptChanges();
//Populate the list of categories
lstPublisher.DataSource = dt;
lstPublisher.DataValueField = "country";
lstPublisher.DataTextField = "country";
lstPublisher.DataBind();
lstPublisher.Items.Insert(0, "--Select--");
lstAuthor.Enabled = false;
lstTitle.Enabled = false;
}
/*###########################################################################################*/
private void FillStates(string countryID)
{
DataSet ds = (DataSet)Cache["InfoToFilter"];
ds = GetInfoFromDB();
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
dr["country"] = AsciiToString(dr["country"].ToString());
dr["states"] = AsciiToString(dr["states"].ToString());
}
dt.AcceptChanges();
DataView view = new DataView();
view.Table = ds.Tables[0];
string filter = String.Format("country LIKE '{0}'", EscapeLikeValue(countryID));
view.RowFilter = filter;
//Populate the list of categories
lstAuthor.DataSource = view;
lstAuthor.DataValueField = "ID";
lstAuthor.DataTextField = "states";
lstAuthor.DataBind();
lstAuthor.Items.Insert(0, "--Select--");
}
/*###########################################################################################*/
private void FillCities(string statesID)
{
DataSet ds = (DataSet)Cache["InfoToFilter"];
ds = GetInfoFromDB();
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
dr["cities"] = AsciiToString(dr["cities"].ToString());
dr["states"] = AsciiToString(dr["states"].ToString());
}
dt.AcceptChanges();
DataView view = new DataView();
view.Table = ds.Tables[0];
string filter = String.Format("states LIKE '{0}'", EscapeLikeValue(statesID));
view.RowFilter = filter;
//Populate the list of categories
lstTitle.DataSource = view;
lstTitle.DataValueField = "ID";
lstTitle.DataTextField = "cities";
lstTitle.DataBind();
lstTitle.Items.Insert(0, "--Select--");
}
/*###########################################################################################*/
private DataSet GetInfoFromDB()
{
//Read the connection string from Web.config
string connectionString = ConfigurationManager.ConnectionStrings["Application"].ConnectionString;
OleDbDataAdapter adp = new OleDbDataAdapter("SELECT Id, country, states, cities FROM myTable", connectionString);
DataSet ds = new DataSet();
adp.Fill(ds);
return ds;
}
/*###########################################################################################*/
private DataSet GetInfoFromDB2()
{
//Read the connection string from Web.config
string connectionString = ConfigurationManager.ConnectionStrings["Application"].ConnectionString;
OleDbDataAdapter adp = new OleDbDataAdapter("SELECT DISTINCT country FROM myTable", connectionString);
DataSet ds = new DataSet();
adp.Fill(ds);
return ds;
}