472,145 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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_SelectedIndexChanged(object
sender, System.EventArgs e)
// the second control
private void ddlCantieri_SelectedIndexChanged(object
sender, System.EventArgs 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.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace SAL_SMAU
{
/// <summary>
/// Summary description for anagraficaClienti.
/// </summary>
public class anagraficaClienti : System.Web.UI.Page
{
#region oggetti grafici
protected System.Web.UI.WebControls.Button
btIndietro;
protected
System.Web.UI.WebControls.TextBox tbRagioneSociale;
protected System.Web.UI.WebControls.Label
Label4;
protected
System.Web.UI.WebControls.TextBox tbCodice;
protected System.Web.UI.WebControls.Label
Label3;
protected System.Web.UI.WebControls.Label
Label2;
protected
System.Web.UI.WebControls.ListBox lbAree;
protected System.Web.UI.WebControls.Label
Label1;
protected
System.Web.UI.WebControls.DropDownList ddlClienti;
protected System.Web.UI.WebControls.Label
Label14;
protected
System.Web.UI.WebControls.TextBox tbIndirizzo;
protected System.Web.UI.WebControls.Label
Label5;
protected System.Web.UI.WebControls.Label
Label6;
protected
System.Web.UI.WebControls.TextBox tbProvincia;
protected System.Web.UI.WebControls.Label
Label7;
protected
System.Web.UI.WebControls.TextBox tbPIVA;
protected System.Web.UI.WebControls.Label
Label8;
protected
System.Web.UI.WebControls.TextBox tbTelefono;
protected System.Web.UI.WebControls.Label
Label9;
protected
System.Web.UI.WebControls.TextBox tbFAX;
protected
System.Web.UI.WebControls.TextBox tbPaeseCantiere;
protected System.Web.UI.WebControls.Label
Label13;
protected
System.Web.UI.WebControls.TextBox tbTelefonoCantiere;
protected System.Web.UI.WebControls.Label
Label16;
protected
System.Web.UI.WebControls.TextBox tbProvinciaCantiere;
protected System.Web.UI.WebControls.Label
Label17;
protected
System.Web.UI.WebControls.TextBox tbIndirizzoCantiere;
protected System.Web.UI.WebControls.Label
Label18;
protected
System.Web.UI.WebControls.TextBox tbPersonaRiferimento;
protected System.Web.UI.WebControls.Label
Label12;
protected
System.Web.UI.WebControls.TextBox tbTipoArea;
protected System.Web.UI.WebControls.Label
Label19;
protected System.Web.UI.WebControls.Image
Image1;
protected System.Web.UI.WebControls.Image
Image2;
protected
System.Web.UI.WebControls.DropDownList ddlCantieri;
protected
System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Label
Label15;
#endregion

private void Page_Load(object sender,
System.EventArgs e)
{
if (!this.IsPostBack)
{
// imposto la sorgente di
dati
this.ddlClienti.DataSource
= GestoreAnagraficheClienti.caricaElencoClienti();
// la descrizione del
cliente come valore visualizzato

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

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

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

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

this.ddlClienti.SelectedIndexChanged += new
System.EventHandler(this.ddlClienti_SelectedIndexC hanged);
this.btIndietro.Click += new
System.EventHandler(this.btIndietro_Click);

this.ddlCantieri.SelectedIndexChanged += new
System.EventHandler(this.ddlCantieri_SelectedIndex Changed);

this.DropDownList1.SelectedIndexChanged += new
System.EventHandler
(this.DropDownList1_SelectedIndexChanged);
this.Load += new
System.EventHandler(this.Page_Load);

}
#endregion

private void btIndietro_Click(object
sender, System.EventArgs e)
{
this.Session.RemoveAll();
// vado alla pagina dei clienti
this.Response.Redirect
("sceltaSAL.aspx");
}

private void
ddlClienti_SelectedIndexChanged(object sender,
System.EventArgs e)
{
/*if(this.Session["cliente"] !=
null)
{

if (this.Session
["cliente"].ToString() != this.ddlClienti.SelectedValue)
{
this.sceltaCliente
();
this.Label1.Text
= "Ciao1";
}
}
else
{
this.sceltaCliente();
this.Label1.Text = "Ciao1";
}*/
//if (!this.IsPostBack)
//{
this.sceltaCliente();
//}

}

private void sceltaCliente()
{
this.Session.Remove("cliente");
this.Session.Add("cliente",
this.ddlClienti.SelectedValue);
DataSet ds =
GestoreAnagraficheClienti.caricaElencoCantieri
(this.ddlClienti.SelectedValue);
// imposto la sorgente di dati
this.ddlCantieri.DataSource = ds;
// la descrizione del cantiere
come valore visualizzato
this.ddlCantieri.DataTextField
= "cantiere_long";
// il codice come valore nascosto
this.ddlCantieri.DataValueField
= "id_cantiere";
// connetto i dati
this.ddlCantieri.DataBind();
// imposto la sorgente di dati
this.DropDownList1.DataSource = ds;
// la descrizione del cantiere
come valore visualizzato
this.DropDownList1.DataTextField
= "cantiere_long";
// il codice come valore nascosto
this.DropDownList1.DataValueField
= "id_cantiere";
// connetto i dati
this.DropDownList1.DataBind();

// memorizzo i dati del cliente
CommonValues.InformazioniCliente
clienteTrovato =
GestoreAnagraficheClienti.caricaInfoCliente
(this.ddlClienti.SelectedValue);
// assegno i valori
this.tbCodice.Text =
this.ddlClienti.SelectedValue;
this.tbFAX.Text =
clienteTrovato.FAX;
this.tbIndirizzo.Text =
clienteTrovato.INDIRIZZO;
this.tbPIVA.Text =
clienteTrovato.PARTITAIVA;
this.tbProvincia.Text =
clienteTrovato.PROVINCIA;
this.tbRagioneSociale.Text =
clienteTrovato.RAGIONESOCIALE;
this.tbTelefono.Text =
clienteTrovato.TELEFONO;
}

private void
ddlCantieri_SelectedIndexChanged(object sender,
System.EventArgs e)
{
/*if(this.Session["cantiere"] !=
null)
{

if
(this.ddlCantieri.SelectedValue.ToString() != this.Session
["cantiere"].ToString())
{
this.sceltaCantiere
();
}

}
else
{
this.sceltaCantiere();
}*/
this.Label1.Text = "ciao2!";
//this.sceltaCantiere();
}

private void sceltaCantiere()
{
this.Session.Remove("cantiere");
this.Session.Add("cantiere",
this.ddlCantieri.SelectedValue);

DataSet ds =
GestoreAnagraficheClienti.caricaElencoAree(

this.ddlClienti.SelectedValue,
this.ddlCantieri.SelectedValue);
// imposto la sorgente di dati
this.lbAree.DataSource = ds;
// la descrizione del cantiere
come valore visualizzato
this.lbAree.DataTextField
= "area_long";
// il codice come valore nascosto
this.lbAree.DataValueField
= "id_area";
// connetto i dati
this.lbAree.DataBind();
}

private void
DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
DataSet ds =
GestoreAnagraficheClienti.caricaElencoAree(

this.ddlClienti.SelectedValue,

this.DropDownList1.SelectedValue);
// imposto la sorgente di dati
this.lbAree.DataSource = ds;
// la descrizione del cantiere
come valore visualizzato
this.lbAree.DataTextField
= "area_long";
// il codice come valore nascosto
this.lbAree.DataValueField
= "id_area";
// connetto i dati
this.lbAree.DataBind();

}

}
}
using System;
using System.Data;
using System.Data.Odbc;

namespace SAL_SMAU
{
/// <summary>
/// Summary description for
gestoreAnagraficheClienti.
/// </summary>
public class GestoreAnagraficheClienti
{
/// <summary>
/// Carica tutti i clienti
/// </summary>
/// <returns>restituisce il dataset
popolato con i clienti oppure null
/// in caso di errore</returns>
public static DataSet caricaElencoClienti()
{
try
{
// Operazioni di
connessione al Database, ed esecuzione Query
OdbcConnection
myConnection = new OdbcConnection(CommonValues.connString);

myConnection.Open();
// query caricamento
clienti
string queryCarClienti
= "SELECT id_cliente, cliente_long, indirizzoSede " +
"FROM
ANAGRAFICA_CLIENTI " +
"ORDER BY
cliente_long";
// eseguo la query
OdbcDataAdapter da = new
OdbcDataAdapter(queryCarClienti, CommonValues.connString);

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

// popolo il dataset
da.Fill
(ds, "Anagrafica_Clienti");
// chiudo connessione
myConnection.Close();
// restituisco dataset
return ds;
}
catch
{
return null;
}
}
/// <summary>
/// Caricamento delle informazioni
relative al cliente.
/// </summary>
/// <param name="codCliente"></param>
/// <returns></returns>
public static
CommonValues.InformazioniCliente caricaInfoCliente(string
codCliente)
{

CommonValues.InformazioniCliente
infoClienteTrovato;
// connessione al database
OdbcConnection myConnection = new
OdbcConnection(CommonValues.connString);
myConnection.Open();
// interrogazione dati del cliente
specificato dal codice
string queryCarCliente = "SELECT
Cliente_Long, provinciaSede, indirizzoSede, piva, " +
"telefono, fax " +
"FROM
ANAGRAFICA_CLIENTI " +
"WHERE id_cliente = '" +
codCliente + "' " +
"ORDER BY Cliente_Long";
// preparo il comando per la
esecuzione
OdbcCommand myCommand = new
OdbcCommand(queryCarCliente, myConnection);
// eseguo la query
OdbcDataReader myReader =
myCommand.ExecuteReader();
myReader.Read();

// memorizzo i dati nel
differenziale di supporto
infoClienteTrovato = new
CommonValues.InformazioniCliente(myReader.GetValue
(0).ToString(),
myReader.GetValue
(1).ToString(),
myReader.GetValue
(2).ToString(),
myReader.GetValue
(3).ToString(),
myReader.GetValue
(4).ToString(),
myReader.GetValue
(5).ToString());
return infoClienteTrovato;
}
/// <summary>
/// Carica tutti i cantieri del cliente
/// </summary>
/// <param name="codCliente">il codice del
cliente</param>
/// <returns>restituisce il dataset
popolato con i cantieri del cliente oppure null
/// in caso di errore</returns>
public static DataSet caricaElencoCantieri
(string codCliente)
{
try
{
// Operazioni di
connessione al Database, ed esecuzione Query
OdbcConnection
myConnection = new OdbcConnection(CommonValues.connString);

myConnection.Open();
// query caricamento
clienti
string queryCarCantieri
= "SELECT id_cantiere, cantiere_long " +
"FROM
ANAGRAFICA_CANTIERI " +
"WHERE id_cantiere = '" +
codCliente + "' " +
"ORDER BY cantiere_long";
// eseguo la query
OdbcDataAdapter da = new
OdbcDataAdapter(queryCarCantieri, CommonValues.connString);

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

// popolo il dataset
da.Fill
(ds, "Anagrafica_Cantieri");
// chiudo connessione
myConnection.Close();
// restituisco dataset
return ds;
}
catch
{
return null;
}
}

/// <summary>
/// Caricamento delle informazioni
relative al cantiere.
/// </summary>
/// <param name="codCliente"></param>
/// <returns></returns>
public static
CommonValues.InformazioniCantiere caricaInfoCantiere
(string codCantiere)
{

CommonValues.InformazioniCantiere
infoCantiereTrovato;
// connessione al database
OdbcConnection myConnection = new
OdbcConnection(CommonValues.connString);
myConnection.Open();
// interrogazione dati del
cantiere specificato dal codice
string queryCarCantiere = "SELECT
cantiere_long, indirizzo, provincia, telefono, " +
"paese " +
"FROM
ANAGRAFICA_CANTIERE " +
"WHERE id_cantiere = '" +
codCantiere + "' " +
"ORDER BY cantiere_long";
// preparo il comando per la
esecuzione
OdbcCommand myCommand = new
OdbcCommand(queryCarCantiere, myConnection);
// eseguo la query
OdbcDataReader myReader =
myCommand.ExecuteReader();
myReader.Read();

// memorizzo i dati nel
differenziale di supporto
infoCantiereTrovato = new
CommonValues.InformazioniCantiere(myReader.GetValu e
(0).ToString(),
myReader.GetValue
(1).ToString(),
myReader.GetValue
(2).ToString(),
myReader.GetValue
(3).ToString(),
myReader.GetValue
(4).ToString());
return infoCantiereTrovato;
}
/// <summary>
/// Carica tutte le aree del cantiere
/// </summary>
/// <param name="codCliente">il codice del
cliente</param>
/// <param name="codCantiere">il codice
del cantiere</param>
/// <returns>restituisce il dataset
popolato con le aree del cantiere oppure null
/// in caso di errore</returns>
public static DataSet caricaElencoAree
(string codCliente, string codCantiere)
{
try
{
// Operazioni di
connessione al Database, ed esecuzione Query
OdbcConnection
myConnection = new OdbcConnection(CommonValues.connString);

myConnection.Open();
// query caricamento
clienti
string queryCarCantieri
= "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(queryCarCantieri, CommonValues.connString);

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

// popolo il dataset
da.Fill
(ds, "Anagrafica_Aree");
// chiudo connessione
myConnection.Close();
// restituisco dataset
return ds;
}
catch
{
return null;
}
}

}
}

Nov 15 '05 #1
0 1627

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Robin Bonin | last post: by
4 posts views Thread by Amy Snyder | last post: by
2 posts views Thread by Yoshitha | last post: by
5 posts views Thread by Vigneshwar Pilli via DotNetMonster.com | last post: by
2 posts views Thread by Mike Collins | last post: by
2 posts views Thread by newsgroups.jd | last post: by
9 posts views Thread by thebison | last post: by
5 posts views Thread by krishnakant Mane | 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.