Solved

binding XmlDataSource to CheckBoxList

Posted on 2013-06-03
2
258 Views
Last Modified: 2013-06-20
Please see attached Image (lessonPage)

I want to have these checkboxes on the page, but powered from an xml file

Now look at the image (Code) and you will see what I have so far (which doesn't work)

to get a working example, i just want to show all the CATEGORIES items as checkboxes

here is the XML
    <Categories>
        <Item SearchText="Creation">Creation</Item>
        <Item SearchText="The Flood">TheFlood</Item>
        <Item SearchText="Gods Chosen People">GodsChosenPeople</Item>
        <Item SearchText="Commandments">Commandments</Item>
        <Item SearchText="The Judges">TheJudges</Item>
        <Item SearchText="The Kings">TheKings</Item>
        <Item SearchText="The Prophets">TheProphets</Item>
        <Item SearchText="Jesus' Birth Christmas">JesusBirthChristmas</Item>
        <Item SearchText="Jesus' Death Easter">JesusDeathEaster</Item>
        <Item SearchText="Parables">TheParables</Item>
        <Item SearchText="Miracles">TheMiracles</Item>
        <Item SearchText="Disciples/Apostles">TheDisciples/Apostles</Item>
        <Item SearchText="People Jesus Met">PeopleJesusMet</Item>
        <Item SearchText="The Early Church">TheEarlyChurch</Item>
    </Categories>

Open in new window


and here is what i've used for the ascx control
<asp:CheckBoxList 
    ID="CheckBoxList1" 
    runat="server" 
    DataSourceID="XmlDataSource1"
    DataTextField="SearchText"  
    >
    </asp:CheckBoxList>

<asp:XmlDataSource  ID="XmlDataSource1" 
                    runat="server" 
                    DataFile="~/LanguageXmlFiles/SearchFilter.xml" 
                    XPath="/BesSearch/Categories"></asp:XmlDataSource>

Open in new window


however it doesn't work and i've no idea why
Capture.JPG
lessonpage.jpg
0
Comment
Question by:websss
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
Comment Utility
Seems you're only missing the last level in the XPath property of your XmlDataSource; add /Item:
<asp:XmlDataSource  ID="XmlDataSource1" 
                    runat="server" 
                    DataFile="~/LanguageXmlFiles/SearchFilter.xml" 
                    XPath="/BesSearch/Categories/Item"></asp:XmlDataSource>

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
Comment Utility
By the way, the text that you have inside the Item nodes (without the spaces) might be what you want to use for the DataValueField property of your CheckBoxList. If that's the case then I think (haven't used it an awful lot myself yet) that you need an xsl transformation. Should be a relatively simple one in this case, but still it could be easier to make sure anything you want to use is contained in attributes, for example:
<Item SearchText="The Flood" ID="TheFlood" />

Open in new window

Then you could use:
<asp:CheckBoxList 
    ID="CheckBoxList1" 
    runat="server" 
    DataSourceID="XmlDataSource1"
    DataTextField="SearchText"  
    DataValueField="ID"
    >
    </asp:CheckBoxList>

Open in new window

Then again, if you don't need that part specifically, you can forget about this part ;-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now