Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 755
  • Last Modified:

Populate Combobox with Simple XML or Text File

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
brian2k1
Asked:
brian2k1
  • 2
  • 2
1 Solution
 
mmarinovCommented:
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
 
brian2k1Author Commented:
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
 
mmarinovCommented:
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
 
brian2k1Author Commented:
Awesome! Thanks very much. I knew it was that simple but I couldn't find any good examples.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now