Solved

Populate Combobox with Simple XML or Text File

Posted on 2004-08-25
4
728 Views
Last Modified: 2008-03-06
Please submit VB.NET code for examples, I'm familiar and use C# from time to time but I'm most familiar with VB.NET.

I would like to know how to populate a ComboBox with data from an XML file or delimited text file as shown below:

XML

<templates>
    <template>
        <name>MyTemplate</name>
        <path>MyTemplatePath</path>
    </template>
</templates>

Plain Text Tab Delimited

Mytemplate       MyTemplatePath

Thanks in advanced.
0
Comment
Question by:brian2k1
  • 2
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 total points
Comment Utility
Hi,

use this:

        If Not IsPostBack Then
            Dim _ds As DataSet = New DataSet
            _ds.ReadXml(Request.ServerVariables("APPL_PHYSICAL_PATH") & "/XMLFile1.xml")
            DropDownList1.DataSource = _ds.Tables(0)
            DropDownList1.DataTextField = "name"
            DropDownList1.DataValueField = "path"
            DropDownList1.DataBind()
        End If

Regards,
B..M
0
 
LVL 1

Author Comment

by:brian2k1
Comment Utility
I posted in the wrong category this was a VB.NET project using WinForms so it is a combo box not a dropdownlist. Do you know the way to use the ComboBox in the same way?

Thanks.
0
 
LVL 28

Expert Comment

by:mmarinov
Comment Utility
the way is absolutelly the same, just you have to replace DataTextField with DisplayMember
DataValueMember with ValueMember and skip the DataBind() method

Regards,
B..M
0
 
LVL 1

Author Comment

by:brian2k1
Comment Utility
Awesome! Thanks very much. I knew it was that simple but I couldn't find any good examples.
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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

10 Experts available now in Live!

Get 1:1 Help Now