Solved

Populate Combobox with Simple XML or Text File

Posted on 2004-08-25
4
735 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
ID: 11889772
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
ID: 11889890
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
ID: 11889906
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
ID: 11889944
Awesome! Thanks very much. I knew it was that simple but I couldn't find any good examples.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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

16 Experts available now in Live!

Get 1:1 Help Now