0

我一直在尝试将 xml 文件中的属性绑定到包含唯一值的下拉列表。该属性是“季节”标签中的“年份”。示例 xml 文件仅包含一个季节的单个值,但确实会出现多个值。但是,行源数据应仅包含每个季节一次。到目前为止,我还没有运气在下拉列表中显示季节。我在 XmlDataSource 的 XPath 中尝试了几个不同的选项,但无济于事。

有人可以帮我吗?

以下是部分页面代码:

 <%@ Page Title="Activiteiten" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Activities_past_CPY.aspx.cs" Inherits="LoadLectureList.Activities" />

 <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">


  <p>
    <asp:DropDownList ID="Seasonlist" runat="server" Width="130" DataSourceID="XmlDataSource2" AppendDataBoundItems="true" />
  </p>

    <p>
    <asp:XmlDataSource ID="XmlDataSource2" runat="server" 
        DataFile="~/Lectures.xml" 
        XPath="//lectures/season[@yearno]/lecture" />

  </p>

  </asp:Content>

这是 XML 文件:

`<?xml version="1.0" encoding="UTF-8"?>
<lectures>
  <season yearno="2012">
    <lecture>
      <date>26 september 2011</date>
      <speaker>Dhr. Sylvain Ephimenco</speaker>
      <speakerdsc>
          Experience of the speaker.
      </speakerdsc>
      <subject>De Arabische volksopstanden</subject>
      <subjectdsc>
          Interesting subject
      </subjectdsc>
      <speakerpic>sylvain-ephimenco.jpg</speakerpic>
      <subjectpic1></subjectpic1>
      <subjectpic2></subjectpic2>
    </lecture>
  </season>
  <season yearno="2013">
    <lecture>
      <date>14 januari 2013</date>
      <speaker>Mr. Wim A. Egger</speaker>
      <speakerdsc>
        More experience of this speaker.
      </speakerdsc>
      <subject>Surinaamse rug, Joodse buik</subject>
      <subjectdsc>
        Another interesting subject
      </subjectdsc>
      <speakerpic>wim egger.jpg</speakerpic>
      <subjectpic1>rug_buik.jpg</subjectpic1>
      <subjectpic2></subjectpic2>
    </lecture>
  </season>
  <season yearno="2014">
    <lecture>
      <date>10 maart 2014</date>
      <speaker>Drs. C. Weltevrede</speaker>
      <speakerdsc>
        This man's curriculum.
      </speakerdsc>
      <subject>De joodse gemeente van Dordrecht tussen 1933 en heden</subject>
      <subjectdsc>
        Gotta hear this lecture
      </subjectdsc>
      <speakerpic>cees_weltevrede.jpg</speakerpic>
      <subjectpic1>synagoge_dordrecht.jpg</subjectpic1>
      <subjectpic2>tallit.tif</subjectpic2>
    </lecture>
  </season>
  <season yearno="2014">
    <lecture>
          <datum>28 april 2014</datum>
      <speaker>Prof. dr. P. W. van der Horst </speaker>
      <speakerdsc>
        Life course of this speaker.
      </speakerdsc>
      <subject>Joodse cultuur tussen Bijbel en Misjna</subject>
      <subjectdsc>
        Don't miss this one
      </subjectdsc>
      <speakerpic></speakerpic>
      <subjectpic1>talmoed.jpg</subjectpic1>
      <subjectpic2></subjectpic2>
    </lecture>
  </season>
</lectures>
`

我在论坛上搜索并找到了许多方法,但没有一个可以实现我的目标。任何帮助将非常感激。提前致谢。

4

1 回答 1

0

我认为最好的方法是通过数据集读取您的 xml 文件。之后,您可以毫无问题地将数据表绑定到下拉列表。

于 2013-10-13T14:48:57.543 回答