Hello There,
If anyone can help me with pre selecting the options based on query from database.
The code I am trying is as follows, but with this code, the dropdown itself stopes working.
private void PopulateCountries()
{
//String strQuery = "select ID, countryName from CountryTable order by countryName";
using (OleDbConnection con = new OleDbConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["globe"].ConnectionString))
{
using (OleDbCommand cmd = new OleDbCommand("select ID, countryName from CountryTable order by countryName"))
{
using (OleDbDataAdapter sda = new OleDbDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
DropDownCheckBoxes1.DataSource = dt;
DropDownCheckBoxes1.DataTextField = "countryName";
DropDownCheckBoxes1.DataValueField = "ID";
DropDownCheckBoxes1.DataBind();
}
}
}
}
OleDbConnection cn1 = new OleDbConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["globe"].ConnectionString);
OleDbCommand selectcountries = new OleDbCommand("SELECT * FROM prdCountries where prdID=@prdID", cn1);
selectcountries.Parameters.AddWithValue("@prdID", planCode.Text);
cn1.Open();
OleDbDataAdapter sda1 = new OleDbDataAdapter(selectcountries);
DataTable dt1 = new DataTable();
sda1.Fill(dt1);
foreach (DataRow row in dt1.Rows)
{
DropDownCheckBoxes1.SelectedValue = row["ID"].ToString();
}
}
If anyone can help with this.
Thanks.