2013-10-13 151 views
0

我一直在嘗試將xml文件中的屬性綁定到包含唯一值的下拉列表。該屬性是'季節'標籤中的'yearno'。示例xml文件僅包含一個季節的單個值,但會發生多個值。但是,行源數據應包含每個季節一次。 到目前爲止,我已經沒有運氣得到季節顯示在下拉列表中。我在XmlDataSource的XPath中嘗試了幾個不同的選項,但沒有用。從xml填充DropDownList行源

有人可以幫我嗎?

下面的頁面代碼的一部分:

<%@ 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> 
` 

我已經搜查,發現在論壇上很多方法,但沒有一個能夠實現我的目標。任何幫助將非常感激。提前致謝。

+0

我想你的xpath應該是'/ lectures/season/@ yearno' – Anirudha

回答

0

我認爲最好的方法是通過數據集讀取你的XML文件。之後,您可以將數據表綁定到下拉列表中,而不會出現任何問題。