Hallo, > . > > die anderen zwei ddls, die in abhängigkeit von ddlMarke sind, > fülle ich > innerhalb des geladenen controls durch einen postback beim > itemChange des > ddlMarke. wahrscheinlich muss ich die anderen zwei ddls dann > auch von meiner > default.aspx aus füllen, nur wie kann ich das machen, wenn > ich erst nach dem > page_load den gewählten wert meiner ddlMarke abfragen kann ? ? ? :-/ > >
ich habe mal versucht, Dein Problem nach meinem Verständnis mit der Northwind DB nachzubauen. In der tb.aspx wird das Control tb.ascx zu Laufzeit aufgerufen. Außerdem wird die Methode FillDropDownlList1 des UC aufgerufen. Diese holt die Kunden der Northwind und bindet diese an DDL1. Wenn in DDL1 der Index wechselt, werden in DDL 2 alle Bestellungen des Kunden gelistet (in der DDL steht der Einfachheit halber nur der Name des Kunden, relevant ist das Value-Feld von DDL2). Ändert sich nun was in DDL2, werden die Produkte (bzw. deren ID) zu der ausgewählten Bestellung in DDL3 angezeigt. Code anbei. Gruss Alex tb.aspx(.cs): 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 test { /// <summary> /// Zusammenfassung für tb. /// </summary> public class tb : System.Web.UI.Page { protected System.Web.UI.WebControls.PlaceHolder plhtb; private void Page_Load(object sender, System.EventArgs e) { tbuc uc1 = (tbuc)Page.LoadControl("tb.ascx"); uc1.ID = "uc1"; uc1.FillDropDownList1(); plhtb.Controls.Add(uc1); } #region Vom Web Form-Designer generierter Code override protected void OnInit(EventArgs e) { // // CODEGEN: Dieser Aufruf ist für den ASP.NET Web Form-Designer erforderlich. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } } <%@ Page language="c#" Codebehind="tb.aspx.cs" AutoEventWireup="false" Inherits="test.tb" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en"> <head> <title>tb</title> <meta name="vs_defaultClientScript" content="JavaScript" > <meta name="vs_targetSchema" content="http://www.w3.org/1999/xhtml" > </head> <body> <form id="tb" method="post" runat="server"> <asp:placeholder id="plhtb" runat="server" /> </form> </body> </html> tb.ascx(.cs): namespace test { using System; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; /// <summary> /// Zusammenfassung für tb1. /// </summary> public class tbuc : System.Web.UI.UserControl { protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.DropDownList DropDownList2; protected System.Web.UI.WebControls.DropDownList DropDownList3; private void Page_Load(object sender, System.EventArgs e) { } public void FillDropDownList1() { DropDownList1.DataSource = ReadCustomers(); DropDownList1.AutoPostBack = true; DropDownList1.DataValueField = "CustomerID"; DropDownList1.DataTextField = "CompanyName"; DropDownList1.DataBind(); } private DataSet ReadCustomers() { SqlConnection MyNWConn = new SqlConnection("Server=(local)\\NETSDK;Database=Northwind;Trusted_Connection= True"); DataSet MyDataSet = new DataSet(); SqlDataAdapter oCommand = new SqlDataAdapter(); SqlCommand oledbcmd = new SqlCommand(); oledbcmd.CommandType = CommandType.Text; oledbcmd.CommandText = "Select * from Customers"; oledbcmd.Connection = MyNWConn; oCommand.SelectCommand = oledbcmd; oCommand.Fill(MyDataSet,"Customers"); MyNWConn.Close(); return MyDataSet; } private DataSet ReadOrders(string CustomerID) { SqlConnection MyNWConn = new SqlConnection("Server=(local)\\NETSDK;Database=Northwind;Trusted_Connection= True"); DataSet MyDataSet = new DataSet(); SqlDataAdapter oCommand = new SqlDataAdapter(); SqlCommand oledbcmd = new SqlCommand(); oledbcmd.CommandType = CommandType.Text; oledbcmd.CommandText = "Select * from Orders WHERE CustomerID = @CustomerID"; oledbcmd.Connection = MyNWConn; oledbcmd.Parameters.Add("@CustomerID", CustomerID); oCommand.SelectCommand = oledbcmd; oCommand.Fill(MyDataSet,"Orders"); MyNWConn.Close(); return MyDataSet; } private DataSet ReadOrderDetails(int OrderID) { SqlConnection MyNWConn = new SqlConnection("Server=(local)\\NETSDK;Database=Northwind;Trusted_Connection= True"); DataSet MyDataSet = new DataSet(); SqlDataAdapter oCommand = new SqlDataAdapter(); SqlCommand oledbcmd = new SqlCommand(); oledbcmd.CommandType = CommandType.Text; oledbcmd.CommandText = "Select * from [Order Details] WHERE OrderID = @OrderID"; oledbcmd.Connection = MyNWConn; oledbcmd.Parameters.Add("@OrderID", OrderID); oCommand.SelectCommand = oledbcmd; oCommand.Fill(MyDataSet,"Orders"); MyNWConn.Close(); return MyDataSet; } #region Vom Web Form-Designer generierter Code override protected void OnInit(EventArgs e) { // // CODEGEN: Dieser Aufruf ist für den ASP.NET Web Form-Designer erforderlich. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Erforderliche Methode für die Designerunterstützung /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> private void InitializeComponent() { this.Load += new EventHandler(this.Page_Load); this.DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged); this.DropDownList2.SelectedIndexChanged += new EventHandler(DropDownList2_SelectedIndexChanged); } #endregion private void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DropDownList2.DataSource = ReadOrders(DropDownList1.Items[DropDownList1.SelectedIndex].Value); DropDownList2.AutoPostBack = true; DropDownList2.DataValueField = "OrderID"; DropDownList2.DataTextField = "ShipName"; DropDownList2.DataBind(); } private void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { DropDownList3.DataSource = ReadOrderDetails(int.Parse(DropDownList2.Items[DropDownList2.SelectedIndex]. Value)); DropDownList3.AutoPostBack = true; DropDownList3.DataValueField = "ProductID"; DropDownList3.DataTextField = "ProductID"; DropDownList3.DataBind(); } } } <%@ Control Language="c#" AutoEventWireup="false" Codebehind="tb.ascx.cs" Inherits="test.tbuc" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList><asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList><asp:DropDownList id="DropDownList3" runat="server"></asp:DropDownList> _______________________________________________ Asp.net Mailingliste, Postings senden an: Asp.net@glengamoi.com An-/Abmeldung und Suchfunktion unter: http://www.glengamoi.com/mailman/listinfo/asp.net