All,
I have a search page that has multiple dropdownlist and some textboxes. I can take care of multiple texboxes and single dropdownlist but not multiple dropdownlist. Here is what I have so far on the web page and Page_Load and it works fine for a single dropdownlist box.
<asp:DropDownList ID = "ddlFruit" runat="server"></asp:DropDownList>
<asp:DropDownList ID = "ddlDrink" runat="server"></asp:DropDownList>
<asp:DropDownList ID = "ddlFood" runat="server"></asp:DropDownList>
Back end code:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string myConn= ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(myConn))
{
using (SqlCommand cmd = new SqlCommand("SELECT Fruit FROM TableA"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
ddlCustomers.DataSource = cmd.ExecuteReader();
ddlCustomers.DataTextField = "Fruit";
ddlCustomers.DataBind();
con.Close();
}
}
}
}
When I added the second and third dropdownlist into the Page_Load then it's not binding the result for the second and third dropdownlist. Here is an example of the first and second dropdownlist code:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string myConn= ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(myConn))
{
using (SqlCommand cmd = new SqlCommand("SELECT Fruit FROM TableA"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
ddlCustomers.DataSource = cmd.ExecuteReader();
ddlCustomers.DataTextField = "Fruit";
ddlCustomers.DataBind();
con.Close();
}
}
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Drinks FROM TableA"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
ddlCustomers.DataSource = cmd.ExecuteReader();
ddlCustomers.DataTextField = "Drinks";
ddlCustomers.DataBind();
con.Close();
}
}
}
}
Thanks so much for any input you can provide -
Thanks so much -