472,146 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

Problem with Double Dropdown list in ASP .NET

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
3 3341
bplacker
121 100+
can you post the code where you build your query from the drop downs?
Nov 21 '06 #2
er1
4
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
er1
4
its fixed?
Nov 21 '06 #4

Post your reply

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

Similar topics

2 posts views Thread by Eric Tuomikoski | last post: by
reply views Thread by E . | last post: by
reply views Thread by Manish | last post: by
3 posts views Thread by msnews.microsoft.com | last post: by
2 posts views Thread by Mike Collins | last post: by
5 posts views Thread by jung_h_park | last post: by
2 posts views Thread by sameer | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.