hi alex -
also ich habe jetzt mal genau deinen code implementiert und das problem bestand nach wie vor. aber wie ich schon vermutet habe, liegt es wohl an dem controls.clear ...
ich habe dir hier mal die funktion mitgeschickt, mit der ich die controls zuweise. habe sie jetzt ein wenig abge�ndert und jetzt funzt es soweit, nur dass er mit die ddls immer weiter f�llt. sprich - er l�scht die alten eintr�ge nicht ... vielleicht mache ich auch einfach vom grund auf her was falsch mit der controls-laderei. :-/
'Funktion, die dem Placeholder ein neues Control zuweist
Public Sub changeControl(newControlString As String)
Session("Control") = newControlString
Dim phInhaltChange As Boolean = True if phInhalt.Controls.Count > 0 Then
If NOT phInhalt.Controls(0).ID = Session("Control") Then
phInhaltChange = true
phInhalt.Controls.RemoveAt(0)
Else
phInhaltChange = False
End If
End Ifif phInhaltChange Then
Dim holderControl As Control holderControl = LoadControl(Session("Control") & ".ascx") holderControl.ID = Session("Control")
'Dim webPartType As Type = System.Type.GetType(newControlString)
Select Case newControlString
'H�ndler Login Control wurde geladen
Case "LoginHaendler"
AddHandler CType(holderControl, LoginHaendler).NewControl, AddressOf Me.changeControlHandle
'Kunden registrieren Control wurde geladen
Case "KundenReg"
AddHandler CType(holderControl, KundenReg).NewControl, AddressOf Me.changeControlHandle
CType(holderControl, KundenReg).loadAnrede
'KundenIntern Control wurde geladen
Case "KundenIntern"
AddHandler CType(holderControl, KundenIntern).NewControl, AddressOf Me.changeControlHandle
CType(holderControl, KundenIntern).loadAnrede
'Firmenprofil Control wurde geladen
Case "Firmenprofil"
AddHandler CType(holderControl, Firmenprofil).NewControl, AddressOf Me.changeControlHandle
'Downloads Control wurde geladen
Case "Download"
AddHandler CType(holderControl, Download).NewControl, AddressOf Me.changeControlHandle
CType(holderControl, Download).getXml()
'Kontakt Control wurde geladen
Case "Anfrage"
AddHandler CType(holderControl, Anfrage).NewControl, AddressOf Me.changeControlHandle
'Wegbeschreibung Control wurde geladen
Case "Wegbeschreibung"
AddHandler CType(holderControl, Wegbeschreibung).NewControl, AddressOf Me.changeControlHandle
Case "Service"
AddHandler CType(holderControl, Service).NewControl, AddressOf Me.changeControlHandle
Case "Impressum"
AddHandler CType(holderControl, Impressum).NewControl, AddressOf Me.changeControlHandle
Case "SucheKFZ"
Dim functions As FunctionClass = New FunctionClass
functions._checkCache()AddHandler CType(holderControl, SucheKFZ).NewControl, AddressOf Me.changeControlHandle
CType(holderControl, SucheKFZ).fillddlStandards()
CType(holderControl, SucheKFZ).fillddlMarke()
End Select
phInhalt.Controls.Add(holderControl)
End If----- Original Message ----- From: "Alexander Zeitler" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, December 30, 2004 10:39 AM
Subject: RE: [Asp.net] DropDownList Problem
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);
}
#endregionprivate 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: [email protected] An-/Abmeldung und Suchfunktion unter: http://www.glengamoi.com/mailman/listinfo/asp.net
_______________________________________________ Asp.net Mailingliste, Postings senden an: [email protected] An-/Abmeldung und Suchfunktion unter: http://www.glengamoi.com/mailman/listinfo/asp.net
