473,683 Members | 3,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Double Dropdown list in ASP .NET

4 New Member
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.IsPos tBack)> 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 3521
bplacker
121 New Member
can you post the code where you build your query from the drop downs?
Nov 21 '06 #2
er1
4 New Member
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.P age {
public string ddlCustval;
public string ddlCustofCustva l;

protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlConnection cn_custdrpdwn = new
SqlConnection(C onfigurationMan ager.Connection Strings["OPDv1Connectio nString"].ToString()))
{
//open the connection with database
cn_custdrpdwn.O pen();

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

string sql_custdrpdwn = "SELECT DISTINCT CustomerNameLon g FROM Customers";

cmd_custdrpdwn. CommandText = sql_custdrpdwn;

SqlDataAdapter Adapter_custdrp dwn = new SqlDataAdapter( );
Adapter_custdrp dwn.SelectComma nd = cmd_custdrpdwn;

DataSet ds_custdrpdwn = new DataSet();

Adapter_custdrp dwn.Fill(ds_cus tdrpdwn);

ddlCust.DataSou rce = ds_custdrpdwn;
ddlCust.DataTex tField = "CustomerNameLo ng";
ddlCust.DataVal ueField = "CustomerID ";
ddlCust.DataBin d();

mygrid1.DataSou rce = ds_custdrpdwn;
mygrid1.DataBin d();

cn_custdrpdwn.C lose();

}
} // end of IsPostBack

using (SqlConnection cn_custofcustdr pdwn = new
SqlConnection(C onfigurationMan ager.Connection Strings["OPDv1Connectio nString"].ToString()))
{
//open the connection with database
cn_custofcustdr pdwn.Open();

SqlCommand cmd_custofcustd rpdwn = new SqlCommand();
cmd_custofcustd rpdwn.Connectio n = cn_custofcustdr pdwn;

// set sql query
string sql_custofcustd rpdwn = "SELECT distinct CustofCust FROM CustomersofCust omer WHERE (cocCustomerID = '" + ddlCust.Selecte dItem.Value + "')

cmd_custofcustd rpdwn.CommandTe xt = sql_custofcustd rpdwn;

SqlDataAdapter Adapter_custofc ustdrpdwn = new SqlDataAdapter( );
Adapter_custofc ustdrpdwn.Selec tCommand = cmd_custofcustd rpdwn;

DataSet ds_custofcustdr pdwn = new DataSet();

Adapter_custofc ustdrpdwn.Fill( ds_custofcustdr pdwn);

ddlCustofCust.D ataSource = ds_custofcustdr pdwn;
ddlCustofCust.D ataTextField = "ccdCustomerNam e";
ddlCustofCust.D ataValueField = "ccdCustomerID" ;
ddlCustofCust.D ataBind();

mygrid1.DataSou rce = ds_custofcustdr pdwn;
mygrid1.DataBin d();

cn_custofcustdr pdwn.Close();

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


protected void Button1_Click(o bject sender, EventArgs e)
{
{
using (SqlConnection cn = new
SqlConnection(C onfigurationMan ager.Connection Strings["OPDv1Connectio nString"].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_Custo mer = '" + ddlCust.Selecte dItem.Value + "') AND (ORD_CustomerOf Customer = '" + ddlCustofCust.S electedItem.Val ue + "') ";

cmd.CommandText = sql;

SqlDataAdapter Adapter = new SqlDataAdapter( );
Adapter.SelectC ommand = cmd;

DataSet ds = new DataSet();

Adapter.Fill(ds );
mygrid.DataSour ce = ds;
mygrid.DataBind ();

}
}
}

protected void ddlCustofCust_S electedIndexCha nged(object sender, EventArgs e)
{
ddlCustofCustva l = ddlCustofCust.S electedValue;
Response.Write( "value changed..");
Response.Write( ddlCustofCustva l);
}
Nov 21 '06 #3
er1
4 New Member
its fixed?
Nov 21 '06 #4

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

Similar topics

2
2099
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 problem is I have a variable called Item_Start, that contains a time that is determined from another procedure. I simply wish to auto select the option if it is found. This all happens when the page loads. You can see below I tried, but it failed. How...
3
2577
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 second apears, then when I change the selection in the second I can display it. If I try to repeat this again it's not working anymore. This works fine on several browsers under Windows. Here is the code: <select name="listOrder"...
0
1294
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 dropdown list, a text field, and another dropdown list and a button that represents and add routine to put data into the table. The dropdownlists are populated on the onload event of the controls, they are working fine. Also adding records is...
0
1377
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 is true).. when the user selects one of the items in the dropdown called "New Label" a popup window comes up where the user can add a new label once he adds a new label it is saved to the table and an event is fired from the Popup
3
2070
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
4550
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 set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
5
11897
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 dropdown list control does not retain its SelectedValue. Unless I read the SelectedValue right after the control has been loaded, populated, and assigned with its original value (and of course that is
2
1231
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 from this dropdown, a new thread is created which calls a webservice and the webservice returns the list of cities the vendor is in and this data
9
9689
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 master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
0
8504
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8922
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7582
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5789
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4519
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2934
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.