Solved

Populate Combobox with Simple XML or Text File

Posted on 2004-08-25
4
743 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…

821 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