473,837 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem when controlling two drop down lists

Hi,
I've got two drop down list controls.
When I select a value from the first one I fill the second
one. And when I select a value from the second one I would
like to fill another control.
But after have choose from the first control and filled
the second... when I select something from the second
control I have not the post back event!
I hope to be understandable! I've attached the code that
make problems. It's commented in italian so probably it
will not help so much.
The methods that give me problems are:
// the first control
private void ddlClienti_Sele ctedIndexChange d(object
sender, System.EventArg s e)
// the second control
private void ddlCantieri_Sel ectedIndexChang ed(object
sender, System.EventArg s e)
I've put a label text setting in the second control
instead the code that load the values to fill another
control.

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace SAL_SMAU
{
/// <summary>
/// Summary description for anagraficaClien ti.
/// </summary>
public class anagraficaClien ti : System.Web.UI.P age
{
#region oggetti grafici
protected System.Web.UI.W ebControls.Butt on
btIndietro;
protected
System.Web.UI.W ebControls.Text Box tbRagioneSocial e;
protected System.Web.UI.W ebControls.Labe l
Label4;
protected
System.Web.UI.W ebControls.Text Box tbCodice;
protected System.Web.UI.W ebControls.Labe l
Label3;
protected System.Web.UI.W ebControls.Labe l
Label2;
protected
System.Web.UI.W ebControls.List Box lbAree;
protected System.Web.UI.W ebControls.Labe l
Label1;
protected
System.Web.UI.W ebControls.Drop DownList ddlClienti;
protected System.Web.UI.W ebControls.Labe l
Label14;
protected
System.Web.UI.W ebControls.Text Box tbIndirizzo;
protected System.Web.UI.W ebControls.Labe l
Label5;
protected System.Web.UI.W ebControls.Labe l
Label6;
protected
System.Web.UI.W ebControls.Text Box tbProvincia;
protected System.Web.UI.W ebControls.Labe l
Label7;
protected
System.Web.UI.W ebControls.Text Box tbPIVA;
protected System.Web.UI.W ebControls.Labe l
Label8;
protected
System.Web.UI.W ebControls.Text Box tbTelefono;
protected System.Web.UI.W ebControls.Labe l
Label9;
protected
System.Web.UI.W ebControls.Text Box tbFAX;
protected
System.Web.UI.W ebControls.Text Box tbPaeseCantiere ;
protected System.Web.UI.W ebControls.Labe l
Label13;
protected
System.Web.UI.W ebControls.Text Box tbTelefonoCanti ere;
protected System.Web.UI.W ebControls.Labe l
Label16;
protected
System.Web.UI.W ebControls.Text Box tbProvinciaCant iere;
protected System.Web.UI.W ebControls.Labe l
Label17;
protected
System.Web.UI.W ebControls.Text Box tbIndirizzoCant iere;
protected System.Web.UI.W ebControls.Labe l
Label18;
protected
System.Web.UI.W ebControls.Text Box tbPersonaRiferi mento;
protected System.Web.UI.W ebControls.Labe l
Label12;
protected
System.Web.UI.W ebControls.Text Box tbTipoArea;
protected System.Web.UI.W ebControls.Labe l
Label19;
protected System.Web.UI.W ebControls.Imag e
Image1;
protected System.Web.UI.W ebControls.Imag e
Image2;
protected
System.Web.UI.W ebControls.Drop DownList ddlCantieri;
protected
System.Web.UI.W ebControls.Drop DownList DropDownList1;
protected System.Web.UI.W ebControls.Labe l
Label15;
#endregion

private void Page_Load(objec t sender,
System.EventArg s e)
{
if (!this.IsPostBa ck)
{
// imposto la sorgente di
dati
this.ddlClienti .DataSource
= GestoreAnagrafi cheClienti.cari caElencoClienti ();
// la descrizione del
cliente come valore visualizzato

this.ddlClienti .DataTextField = "cliente_lo ng";
// il codice come valore
nascosto

this.ddlClienti .DataValueField = "id_cliente ";
// connetto i dati
this.ddlClienti .DataBind();
//this.ddlClienti _SelectedIndexC hanged(null, null);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeCompo nent()
{

this.ddlClienti .SelectedIndexC hanged += new
System.EventHan dler(this.ddlCl ienti_SelectedI ndexChanged);
this.btIndietro .Click += new
System.EventHan dler(this.btInd ietro_Click);

this.ddlCantier i.SelectedIndex Changed += new
System.EventHan dler(this.ddlCa ntieri_Selected IndexChanged);

this.DropDownLi st1.SelectedInd exChanged += new
System.EventHan dler
(this.DropDownL ist1_SelectedIn dexChanged);
this.Load += new
System.EventHan dler(this.Page_ Load);

}
#endregion

private void btIndietro_Clic k(object
sender, System.EventArg s e)
{
this.Session.Re moveAll();
// vado alla pagina dei clienti
this.Response.R edirect
("sceltaSAL.asp x");
}

private void
ddlClienti_Sele ctedIndexChange d(object sender,
System.EventArg s e)
{
/*if(this.Sessio n["cliente"] !=
null)
{

if (this.Session
["cliente"].ToString() != this.ddlClienti .SelectedValue)
{
this.sceltaClie nte
();
this.Label1.Tex t
= "Ciao1";
}
}
else
{
this.sceltaClie nte();
this.Label1.Tex t = "Ciao1";
}*/
//if (!this.IsPostBa ck)
//{
this.sceltaClie nte();
//}

}

private void sceltaCliente()
{
this.Session.Re move("cliente") ;
this.Session.Ad d("cliente",
this.ddlClienti .SelectedValue) ;
DataSet ds =
GestoreAnagrafi cheClienti.cari caElencoCantier i
(this.ddlClient i.SelectedValue );
// imposto la sorgente di dati
this.ddlCantier i.DataSource = ds;
// la descrizione del cantiere
come valore visualizzato
this.ddlCantier i.DataTextField
= "cantiere_long" ;
// il codice come valore nascosto
this.ddlCantier i.DataValueFiel d
= "id_cantier e";
// connetto i dati
this.ddlCantier i.DataBind();
// imposto la sorgente di dati
this.DropDownLi st1.DataSource = ds;
// la descrizione del cantiere
come valore visualizzato
this.DropDownLi st1.DataTextFie ld
= "cantiere_long" ;
// il codice come valore nascosto
this.DropDownLi st1.DataValueFi eld
= "id_cantier e";
// connetto i dati
this.DropDownLi st1.DataBind();

// memorizzo i dati del cliente
CommonValues.In formazioniClien te
clienteTrovato =
GestoreAnagrafi cheClienti.cari caInfoCliente
(this.ddlClient i.SelectedValue );
// assegno i valori
this.tbCodice.T ext =
this.ddlClienti .SelectedValue;
this.tbFAX.Text =
clienteTrovato. FAX;
this.tbIndirizz o.Text =
clienteTrovato. INDIRIZZO;
this.tbPIVA.Tex t =
clienteTrovato. PARTITAIVA;
this.tbProvinci a.Text =
clienteTrovato. PROVINCIA;
this.tbRagioneS ociale.Text =
clienteTrovato. RAGIONESOCIALE;
this.tbTelefono .Text =
clienteTrovato. TELEFONO;
}

private void
ddlCantieri_Sel ectedIndexChang ed(object sender,
System.EventArg s e)
{
/*if(this.Sessio n["cantiere"] !=
null)
{

if
(this.ddlCantie ri.SelectedValu e.ToString() != this.Session
["cantiere"].ToString())
{
this.sceltaCant iere
();
}

}
else
{
this.sceltaCant iere();
}*/
this.Label1.Tex t = "ciao2!";
//this.sceltaCant iere();
}

private void sceltaCantiere( )
{
this.Session.Re move("cantiere" );
this.Session.Ad d("cantiere",
this.ddlCantier i.SelectedValue );

DataSet ds =
GestoreAnagrafi cheClienti.cari caElencoAree(

this.ddlClienti .SelectedValue,
this.ddlCantier i.SelectedValue );
// imposto la sorgente di dati
this.lbAree.Dat aSource = ds;
// la descrizione del cantiere
come valore visualizzato
this.lbAree.Dat aTextField
= "area_long" ;
// il codice come valore nascosto
this.lbAree.Dat aValueField
= "id_area";
// connetto i dati
this.lbAree.Dat aBind();
}

private void
DropDownList1_S electedIndexCha nged(object sender,
System.EventArg s e)
{
DataSet ds =
GestoreAnagrafi cheClienti.cari caElencoAree(

this.ddlClienti .SelectedValue,

this.DropDownLi st1.SelectedVal ue);
// imposto la sorgente di dati
this.lbAree.Dat aSource = ds;
// la descrizione del cantiere
come valore visualizzato
this.lbAree.Dat aTextField
= "area_long" ;
// il codice come valore nascosto
this.lbAree.Dat aValueField
= "id_area";
// connetto i dati
this.lbAree.Dat aBind();

}

}
}
using System;
using System.Data;
using System.Data.Odb c;

namespace SAL_SMAU
{
/// <summary>
/// Summary description for
gestoreAnagrafi cheClienti.
/// </summary>
public class GestoreAnagrafi cheClienti
{
/// <summary>
/// Carica tutti i clienti
/// </summary>
/// <returns>restit uisce il dataset
popolato con i clienti oppure null
/// in caso di errore</returns>
public static DataSet caricaElencoCli enti()
{
try
{
// Operazioni di
connessione al Database, ed esecuzione Query
OdbcConnection
myConnection = new OdbcConnection( CommonValues.co nnString);

myConnection.Op en();
// query caricamento
clienti
string queryCarClienti
= "SELECT id_cliente, cliente_long, indirizzoSede " +
"FROM
ANAGRAFICA_CLIE NTI " +
"ORDER BY
cliente_long";
// eseguo la query
OdbcDataAdapter da = new
OdbcDataAdapter (queryCarClient i, CommonValues.co nnString);

// predispongo oggetto
dataset per essere popolato
DataSet ds = new DataSet();

// popolo il dataset
da.Fill
(ds, "Anagrafica_Cli enti");
// chiudo connessione
myConnection.Cl ose();
// restituisco dataset
return ds;
}
catch
{
return null;
}
}
/// <summary>
/// Caricamento delle informazioni
relative al cliente.
/// </summary>
/// <param name="codClient e"></param>
/// <returns></returns>
public static
CommonValues.In formazioniClien te caricaInfoClien te(string
codCliente)
{

CommonValues.In formazioniClien te
infoClienteTrov ato;
// connessione al database
OdbcConnection myConnection = new
OdbcConnection( CommonValues.co nnString);
myConnection.Op en();
// interrogazione dati del cliente
specificato dal codice
string queryCarCliente = "SELECT
Cliente_Long, provinciaSede, indirizzoSede, piva, " +
"telefono, fax " +
"FROM
ANAGRAFICA_CLIE NTI " +
"WHERE id_cliente = '" +
codCliente + "' " +
"ORDER BY Cliente_Long";
// preparo il comando per la
esecuzione
OdbcCommand myCommand = new
OdbcCommand(que ryCarCliente, myConnection);
// eseguo la query
OdbcDataReader myReader =
myCommand.Execu teReader();
myReader.Read() ;

// memorizzo i dati nel
differenziale di supporto
infoClienteTrov ato = new
CommonValues.In formazioniClien te(myReader.Get Value
(0).ToString(),
myReader.GetVal ue
(1).ToString(),
myReader.GetVal ue
(2).ToString(),
myReader.GetVal ue
(3).ToString(),
myReader.GetVal ue
(4).ToString(),
myReader.GetVal ue
(5).ToString()) ;
return infoClienteTrov ato;
}
/// <summary>
/// Carica tutti i cantieri del cliente
/// </summary>
/// <param name="codClient e">il codice del
cliente</param>
/// <returns>restit uisce il dataset
popolato con i cantieri del cliente oppure null
/// in caso di errore</returns>
public static DataSet caricaElencoCan tieri
(string codCliente)
{
try
{
// Operazioni di
connessione al Database, ed esecuzione Query
OdbcConnection
myConnection = new OdbcConnection( CommonValues.co nnString);

myConnection.Op en();
// query caricamento
clienti
string queryCarCantier i
= "SELECT id_cantiere, cantiere_long " +
"FROM
ANAGRAFICA_CANT IERI " +
"WHERE id_cantiere = '" +
codCliente + "' " +
"ORDER BY cantiere_long";
// eseguo la query
OdbcDataAdapter da = new
OdbcDataAdapter (queryCarCantie ri, CommonValues.co nnString);

// predispongo oggetto
dataset per essere popolato
DataSet ds = new DataSet();

// popolo il dataset
da.Fill
(ds, "Anagrafica_Can tieri");
// chiudo connessione
myConnection.Cl ose();
// restituisco dataset
return ds;
}
catch
{
return null;
}
}

/// <summary>
/// Caricamento delle informazioni
relative al cantiere.
/// </summary>
/// <param name="codClient e"></param>
/// <returns></returns>
public static
CommonValues.In formazioniCanti ere caricaInfoCanti ere
(string codCantiere)
{

CommonValues.In formazioniCanti ere
infoCantiereTro vato;
// connessione al database
OdbcConnection myConnection = new
OdbcConnection( CommonValues.co nnString);
myConnection.Op en();
// interrogazione dati del
cantiere specificato dal codice
string queryCarCantier e = "SELECT
cantiere_long, indirizzo, provincia, telefono, " +
"paese " +
"FROM
ANAGRAFICA_CANT IERE " +
"WHERE id_cantiere = '" +
codCantiere + "' " +
"ORDER BY cantiere_long";
// preparo il comando per la
esecuzione
OdbcCommand myCommand = new
OdbcCommand(que ryCarCantiere, myConnection);
// eseguo la query
OdbcDataReader myReader =
myCommand.Execu teReader();
myReader.Read() ;

// memorizzo i dati nel
differenziale di supporto
infoCantiereTro vato = new
CommonValues.In formazioniCanti ere(myReader.Ge tValue
(0).ToString(),
myReader.GetVal ue
(1).ToString(),
myReader.GetVal ue
(2).ToString(),
myReader.GetVal ue
(3).ToString(),
myReader.GetVal ue
(4).ToString()) ;
return infoCantiereTro vato;
}
/// <summary>
/// Carica tutte le aree del cantiere
/// </summary>
/// <param name="codClient e">il codice del
cliente</param>
/// <param name="codCantie re">il codice
del cantiere</param>
/// <returns>restit uisce il dataset
popolato con le aree del cantiere oppure null
/// in caso di errore</returns>
public static DataSet caricaElencoAre e
(string codCliente, string codCantiere)
{
try
{
// Operazioni di
connessione al Database, ed esecuzione Query
OdbcConnection
myConnection = new OdbcConnection( CommonValues.co nnString);

myConnection.Op en();
// query caricamento
clienti
string queryCarCantier i
= "SELECT id_area, area_long " +
"FROM
ANAGRAFICA_AREE " +
"WHERE id_cliente
= '" + codCliente + "' AND id_cantiere = '" + codCantiere
+ "' " +
"ORDER BY
area_long";
// eseguo la query
OdbcDataAdapter da = new
OdbcDataAdapter (queryCarCantie ri, CommonValues.co nnString);

// predispongo oggetto
dataset per essere popolato
DataSet ds = new DataSet();

// popolo il dataset
da.Fill
(ds, "Anagrafica_Are e");
// chiudo connessione
myConnection.Cl ose();
// restituisco dataset
return ds;
}
catch
{
return null;
}
}

}
}

Nov 15 '05 #1
0 1740

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7425
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the collection that I need. To begin, I am using xsltproc that conmes with Cygwin as my processor. I have no particular affinity to this processor except that it is open source and standards compliant. I don't like M$, but if using a M$ processing...
6
7030
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone changes box1, I want to set the selected index in box2 = 0. When I do this, I dont get an error, but when the page loads, it still has the selected value and not 0. It seems that it is getting the selected value from the viewstate
4
1871
by: Amy Snyder | last post by:
I have a webform that has a listbox and two textboxes. The style property of the text boxes are: style="DISPLAY: none" Based on the selection made in the listbox, one or both textboxes are displayed using javascript. The problem comes when I submit the form. I want the text boxes to stay displayed after submitting the form because there will be values in them. How can I do this with .NET / JavaScript?
2
12627
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will select any skill in 1st drop down list then i'll select % of this skill in the 2nd list box , based on the percentage i've selected in the 2nd list box it has to display 2 sets of drop down list boxes at run time one for selecting skill and
5
4234
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1); System.Data.SqlClient.SqlCommand dbCommand1 = new System.Data.SqlClient.SqlCommand();
2
4559
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:
2
1471
by: newsgroups.jd | last post by:
Thanks for any advice, help in advance... I have 3 dropdownlist that populate based on choice in the previous (nested essentially) Problem is when I hit the back button and make a change in the second or thrid dropdownlist it does not always redirect to the correct site... What I really want to happen is if the back button is pushed then everything clears and all starts from
9
1730
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my database has been made in MSDE. As part of my application, I have a 'Resources' table, which holds employee information. I have the fields FirstName and LastName which are entered in my data capture form which works fine. The problem
5
1496
by: krishnakant Mane | last post by:
hello all. thanks for the help and for pointing me to the proper url for wxpython related issues. I am so happy that I now have a very easy gui library that can do practically every thing with such ease (no flames intended but I was never at so much ease with java swing ). I however have a problem with dates. I am tired searching for some good tutorial that can explain the basic functionality of wx.datetime class and the datetime picker....
0
9852
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10902
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
10583
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
10288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7824
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7014
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
5680
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
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3128
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.