I think every developer had already the situation, that he needed to display or catch certain dependencies. With if-else or switch you can do that, but in case of changes to the logic, you need to get into the source code and change that. Sometimes you don't have the source code or just a compiled version. You can handle this with XML. The environment of this example is framework 3.5 with Linq. I used for output dropdown-lists.
aspx - Seite
Codebehind
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadFirstMenu();
}
}
{
if (!Page.IsPostBack)
{
LoadFirstMenu();
}
}
protected void LoadFirstMenu()
{
Ebene1.Items.Add(new ListItem("Auswahl", "Auswahl"));
XDocument myDocument = XDocument.Load(MapPath("XMLTest.xml"));
var myQuery = from strResult in myDocument.Descendants("Logic").Descendants("Parent") select strResult.Attribute("ID").Value;
foreach (var Item in myQuery)
{
Ebene1.Items.Add(new ListItem(Item, Item));
}
Ebene2.Items.Clear();
Ebene3.Items.Clear();
}
{
Ebene1.Items.Add(new ListItem("Auswahl", "Auswahl"));
XDocument myDocument = XDocument.Load(MapPath("
var myQuery = from strResult in myDocument.Descendants("Logic"
foreach (var Item in myQuery)
{
Ebene1.Items.Add(new ListItem(Item, Item));
}
Ebene2.Items.Clear();
Ebene3.Items.Clear();
}
protected void LoadSecondMenu(object sender, EventArgs e)
{
Ebene2.Items.Clear();
if (Ebene1.SelectedItem.Value != "Auswahl")
{
Ebene2.Items.Add(new ListItem("Auswahl", "Auswahl"));
XDocument myDocument = XDocument.Load(MapPath("XMLTest.xml"));
var myQuery = from strResult in myDocument.Descendants("Logic").Descendants("Parent").Descendants("Child") where strResult.Parent.Attribute("ID").Value == Ebene1.SelectedItem.Value select strResult.Attribute("ID").Value;
foreach (var Item in myQuery)
{
Ebene2.Items.Add(new ListItem(Item, Item));
}
}
Ebene3.Items.Clear();
}
{
Ebene2.Items.Clear();
if (Ebene1.SelectedItem.Value != "Auswahl")
{
Ebene2.Items.Add(new ListItem("Auswahl", "Auswahl"));
XDocument myDocument = XDocument.Load(MapPath("
var myQuery = from strResult in myDocument.Descendants("Logic"
foreach (var Item in myQuery)
{
Ebene2.Items.Add(new ListItem(Item, Item));
}
}
Ebene3.Items.Clear();
}
protected void LoadThirdMenu(object sender, EventArgs e)
{
if (Ebene2.SelectedItem.Value != "Auswahl")
{
Ebene3.Items.Add(new ListItem("Auswahl", "Auswahl"));
XDocument myDocument = XDocument.Load(MapPath("XMLTest.xml"));
var myQuery = from strResult in myDocument.Descendants("Logic").Descendants("Parent").Descendants("Child").Descendants("Child") where strResult.Parent.Attribute("ID").Value == Ebene2.SelectedItem.Value select strResult.Attribute("ID").Value;
foreach (var Item in myQuery)
{
Ebene3.Items.Add(new ListItem(Item, Item));
}
}
}
{
if (Ebene2.SelectedItem.Value != "Auswahl")
{
Ebene3.Items.Add(new ListItem("Auswahl", "Auswahl"));
XDocument myDocument = XDocument.Load(MapPath("
var myQuery = from strResult in myDocument.Descendants("Logic"
foreach (var Item in myQuery)
{
Ebene3.Items.Add(new ListItem(Item, Item));
}
}
}
protected void GetValue(object sender, EventArgs e)
{
if (Ebene3.SelectedItem.Value != "Auswahl")
{
XDocument myDocument = XDocument.Load(MapPath("XMLTest.xml"));
var myQuery = from strResult in myDocument.Descendants("Logic").Descendants("Parent").Descendants("Child").Descendants("Child") where strResult.Attribute("ID").Value == Ebene3.SelectedItem.Value select strResult.Value;
foreach (var Item in myQuery)
{
MyLit.Text = Item;
}
}
}
{
if (Ebene3.SelectedItem.Value != "Auswahl")
{
XDocument myDocument = XDocument.Load(MapPath("
var myQuery = from strResult in myDocument.Descendants("Logic"
foreach (var Item in myQuery)
{
MyLit.Text = Item;
}
}
}
XML Datei
<Logic>
<Parent ID="ParentItem">
<Child ID="Child1.1">
<Child ID="Child1.1.1">TextBlock 1.1.1</Child>
<Child ID="Child1.1.2">TextBlock 1.1.2</Child>
<Child ID="Child1.1.3">TextBlock 1.1.3</Child>
<Child ID="Child1.1.4">TextBlock 1.1.4</Child>
<Child ID="Child1.1.5">TextBlock 1.1.5</Child>
</Child>
<Child ID="Child1.2">
<Child ID="Child1.2.1">TextBlock 1.2.1</Child>
<Child ID="Child1.2.2">TextBlock 1.2.2</Child>
<Child ID="Child1.2.3">TextBlock 1.2.3</Child>
<Child ID="Child1.2.4">TextBlock 1.2.4</Child>
<Child ID="Child1.2.5">TextBlock 1.2.5</Child>
</Child>
<Child ID="Child1.3">
<Child ID="Child1.3.1">TextBlock 1.3.1</Child>
<Child ID="Child1.3.2">TextBlock 1.3.2</Child>
<Child ID="Child1.3.3">TextBlock 1.3.3</Child>
<Child ID="Child1.3.4">TextBlock 1.3.4</Child>
<Child ID="Child1.3.5">TextBlock 1.3.5</Child>
</Child>
</Parent>
<Parent ID="ParentItem2">
<Child ID="Child2.1">
<Child ID="Child2.1.1">TextBlock 2.1.1</Child>
<Child ID="Child2.1.2">TextBlock 2.1.2</Child>
<Child ID="Child2.1.3">TextBlock 2.1.3</Child>
<Child ID="Child2.1.4">TextBlock 2.1.4</Child>
<Child ID="Child2.1.5">TextBlock 2.1.5</Child>
</Child>
<Child ID="Child2.2">
<Child ID="Child2.2.1">TextBlock 2.2.1</Child>
<Child ID="Child2.2.2">TextBlock 2.2.2</Child>
<Child ID="Child2.2.3">TextBlock 2.2.3</Child>
<Child ID="Child2.2.4">TextBlock 2.2.4</Child>
<Child ID="Child2.2.5">TextBlock 2.2.5</Child>
</Child>
</Parent>
<Parent ID="ParentItem3">
<Child ID="Child3.1">
<Child ID="Child3.1.1">TextBlock 3.1.1</Child>
<Child ID="Child3.1.2">TextBlock 3.1.2</Child>
<Child ID="Child3.1.3">TextBlock 3.1.3</Child>
<Child ID="Child3.1.4">TextBlock 3.1.4</Child>
<Child ID="Child3.1.5">TextBlock 3.1.5</Child>
</Child>
<Child ID="Child3.2">
<Child ID="Child3.2.1">TextBlock 3.2.1</Child>
<Child ID="Child3.2.2">TextBlock 3.2.2</Child>
<Child ID="Child3.2.3">TextBlock 3.2.3</Child>
<Child ID="Child3.2.4">TextBlock 3.2.4</Child>
<Child ID="Child3.2.5">TextBlock 3.2.5</Child>
</Child>
<Child ID="Child3.3">
<Child ID="Child3.3.1">TextBlock 3.3.1</Child>
<Child ID="Child3.3.2">TextBlock 3.3.2</Child>
<Child ID="Child3.3.3">TextBlock 3.3.3</Child>
<Child ID="Child3.3.4">TextBlock 3.3.4</Child>
<Child ID="Child3.3.5">TextBlock 3.3.5</Child>
</Child>
<Child ID="Child3.4">
<Child ID="Child3.4.1">TextBlock 3.4.1</Child>
<Child ID="Child3.4.2">TextBlock 3.4.2</Child>
<Child ID="Child3.4.3">TextBlock 3.4.3</Child>
<Child ID="Child3.4.4">TextBlock 3.4.4</Child>
<Child ID="Child3.4.5">TextBlock 3.4.5</Child>
</Child>
</Parent>
<Parent ID="ParentItem4">
<Child ID="Child4.1">
<Child ID="Child4.1.1">TextBlock 4.1.1</Child>
<Child ID="Child4.1.2">TextBlock 4.1.2</Child>
<Child ID="Child4.1.3">TextBlock 4.1.3</Child>
<Child ID="Child4.1.4">TextBlock 4.1.4</Child>
<Child ID="Child4.1.5">TextBlock 4.1.5</Child>
</Child>
<Child ID="Child4.2">
<Child ID="Child4.2.1">TextBlock 4.2.1</Child>
<Child ID="Child4.2.2">TextBlock 4.2.2</Child>
<Child ID="Child4.2.3">TextBlock 4.2.3</Child>
<Child ID="Child4.2.4">TextBlock 4.2.4</Child>
<Child ID="Child4.2.5">TextBlock 4.2.5</Child>
</Child>
</Parent>
</Logic>
Keine Kommentare:
Kommentar veröffentlichen