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;
}
}
}
}