473,395 Members | 1,468 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,395 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 1710

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

Similar topics

5
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...
6
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...
4
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...
2
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...
5
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);...
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...
2
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...
9
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...
5
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.