473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 3493
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

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

Similar topics

2
by: Eric Tuomikoski | last post by:
Im having trouble with server side ASP with Javascript. I have an ADO recordset that returns a list of Times example: 7:00AM. I then populate the option box with the results. (see below) The...
3
by: mtz | last post by:
Hi there, It looks like safari has a problem with innerHTML. I have to change a dropdown depending on a selection in another dropdown. When I change the selection in the first dropdown the...
0
by: E . | last post by:
I seem to be getting nowhere with this problem here is the situation. I have a webform with a data grid populated with the results of a table that has only 3 fields. Then below that are 1...
0
by: Manish | last post by:
Hi All, I'm having this problem I hope someone can help provide a solution for it :) I've this dropdown list box in a usercontrol which I'm populating from the database (it's viewstate property...
3
by: msnews.microsoft.com | last post by:
Hi All, I m facing problem in Server Side Validation. For Example The Scenario is I have two fields on the page 1 Country Dropdown List 2 Province Textbox 3 State Dropdown List
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
2
by: sameer | last post by:
Hi guys, thanks in advance. trying to implement some multithreading here : VS 2003 VB.net winforms I have a dropdown on a form which has list of vendors, when the user selects a vendor...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.