By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,364 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,364 IT Pros & Developers. It's quick & easy.

Problem with Double Dropdown list in ASP .NET

P: 4
Hi all,

I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query based on the values selected on both the dropdown lists. But this part is not working. It picks up right value for the first dropdown list and always takes the FIRST value of the second dropdown list. I am not sure how to make it use the selected value of the second dropdown list??
Since I have to populate the second dropdown list based on the first list selection, I have kept <if(!Page.IsPostBack)> around the first dropdown list only and that makes the value of the first list stay there. If I keep it around both the lists, second list does not get populated at all (which makes sense to me).

Thanks.!! Please help..
Nov 21 '06 #1
Share this Question
Share on Google+
3 Replies


bplacker
100+
P: 121
can you post the code where you build your query from the drop downs?
Nov 21 '06 #2

P: 4
er1
can you post the code where you build your query from the drop downs?
Sure ! Below is the code.

Public partial class SelectDate : System.Web.UI.Page {
public string ddlCustval;
public string ddlCustofCustval;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlConnection cn_custdrpdwn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["OPDv1ConnectionString"].ToString()))
{
//open the connection with database
cn_custdrpdwn.Open();

SqlCommand cmd_custdrpdwn = new SqlCommand();
cmd_custdrpdwn.Connection = cn_custdrpdwn;

string sql_custdrpdwn = "SELECT DISTINCT CustomerNameLong FROM Customers";

cmd_custdrpdwn.CommandText = sql_custdrpdwn;

SqlDataAdapter Adapter_custdrpdwn = new SqlDataAdapter();
Adapter_custdrpdwn.SelectCommand = cmd_custdrpdwn;

DataSet ds_custdrpdwn = new DataSet();

Adapter_custdrpdwn.Fill(ds_custdrpdwn);

ddlCust.DataSource = ds_custdrpdwn;
ddlCust.DataTextField = "CustomerNameLong";
ddlCust.DataValueField = "CustomerID";
ddlCust.DataBind();

mygrid1.DataSource = ds_custdrpdwn;
mygrid1.DataBind();

cn_custdrpdwn.Close();

}
} // end of IsPostBack

using (SqlConnection cn_custofcustdrpdwn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["OPDv1ConnectionString"].ToString()))
{
//open the connection with database
cn_custofcustdrpdwn.Open();

SqlCommand cmd_custofcustdrpdwn = new SqlCommand();
cmd_custofcustdrpdwn.Connection = cn_custofcustdrpdwn;

// set sql query
string sql_custofcustdrpdwn = "SELECT distinct CustofCust FROM CustomersofCustomer WHERE (cocCustomerID = '" + ddlCust.SelectedItem.Value + "')

cmd_custofcustdrpdwn.CommandText = sql_custofcustdrpdwn;

SqlDataAdapter Adapter_custofcustdrpdwn = new SqlDataAdapter();
Adapter_custofcustdrpdwn.SelectCommand = cmd_custofcustdrpdwn;

DataSet ds_custofcustdrpdwn = new DataSet();

Adapter_custofcustdrpdwn.Fill(ds_custofcustdrpdwn) ;

ddlCustofCust.DataSource = ds_custofcustdrpdwn;
ddlCustofCust.DataTextField = "ccdCustomerName";
ddlCustofCust.DataValueField = "ccdCustomerID";
ddlCustofCust.DataBind();

mygrid1.DataSource = ds_custofcustdrpdwn;
mygrid1.DataBind();

cn_custofcustdrpdwn.Close();

}
} // end of IsPostBack
}// end Page_Load


protected void Button1_Click(object sender, EventArgs e)
{
{
using (SqlConnection cn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["OPDv1ConnectionString"].ToString()))
{
//open the connection with database
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;

string sql = "SELECT DISTINCT CustomerName, CustofCust, LName, FName, Address FROM Details WHERE(ORD_Customer = '" + ddlCust.SelectedItem.Value + "') AND (ORD_CustomerOfCustomer = '" + ddlCustofCust.SelectedItem.Value + "') ";

cmd.CommandText = sql;

SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = cmd;

DataSet ds = new DataSet();

Adapter.Fill(ds);
mygrid.DataSource = ds;
mygrid.DataBind();

}
}
}

protected void ddlCustofCust_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCustofCustval = ddlCustofCust.SelectedValue;
Response.Write("value changed..");
Response.Write(ddlCustofCustval);
}
Nov 21 '06 #3

P: 4
er1
its fixed?
Nov 21 '06 #4

Post your reply

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