Solved

Load Listbox from Multiple XML Files

Posted on 2007-04-11
4
723 Views
Last Modified: 2008-01-09
I am at the moment using the following code to load listbox values from a single XML file.  
private string filepath = "C:\\IndexList.xml";

protected void Page_Load(object sender, System.EventArgs e)
{
 if (!IsPostBack)
 {
   DataSet dsIndexes = new DataSet("Indexes");
   dsIndexes.ReadXml(filepath);  
   lstIndexList.DataSource = dsIndexes.Tables[0];
   lstIndexList.DataTextField = dsIndexes.Tables[0].Columns[1].ToString();
   lstIndexList.DataValueField = dsIndexes.Tables[0].Columns[2].ToString();
   lstIndexList.DataBind();
 }
}

now i need to load multiple xml file into the same listbox depends on querystring "id" from a directory "c:\indexlist"

if the querystring is null, it should load listbox from all xml available in C:\indexlist directory else (if id is euqal to "abcd" it should load values from aml file abcd.xml.  How could i code this to work?

Alternatively I am thinking to use the following access database and retrieve the values based on group id value.
Table - Indexes
-------------------
Index_id
group_id
Index_name
Index_url

Table - Groups
------------------
group_id
group_name

Thanks
0
Comment
Question by:thirunachi
4 Comments
 
LVL 5

Accepted Solution

by:
asp_lha earned 250 total points
ID: 18888074
I do not quite understand your sense (I'm poor in english)
but I write some codes, hope this can help you a little :

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then

            Dim dsIndexs As New DataSet("Indexes")

            Dim filePath As String = "C:\temp\"
            Dim queryString As String = Request.QueryString("id")
            ' check the "id" query string
            If Not String.IsNullOrEmpty(queryString) Then
                ' "id" is not emptry or null, then load the xml file
                filePath += queryString + ".xml"
                dsIndexs.ReadXml(filePath)
            Else
                ' "id" is emptry or null, load all of the xml files in target dir
                Dim files As String() = Directory.GetFiles(filePath, "*.xml")
                For i As Integer = 0 To files.Length - 1
                    dsIndexs.ReadXml(files(i))
                Next
            End If

            ListBox1.DataSource = dsIndexs.Tables(2)
            ListBox1.DataTextField = dsIndexs.Tables(2).Columns(0).ToString()
            ListBox1.DataValueField = dsIndexs.Tables(2).Columns(1).ToString()
            ListBox1.DataBind()
        End If

    End Sub
0
 
LVL 18

Assisted Solution

by:Ajay Sharma
Ajay Sharma earned 250 total points
ID: 18888089
to fill the data in the listbox , alternatively u can use the    lstIndexList.items.add method.
code

protected void Page_Load(object sender, System.EventArgs e)
{
 if (!IsPostBack)
 {
   DataSet dsIndexes = new DataSet("Indexes");
   dsIndexes.ReadXml(filepath);  
   lstIndexList.DataSource = dsIndexes.Tables[0];

dim i as integer
 for i=0 to dsindex.tables(0).rows.count-1
lstbox.items.add(dsindex.tables(0).rows(i)(columnnumberhere))
 next

 }
}


i dont know the c# systax so please be understood
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

17 Experts available now in Live!

Get 1:1 Help Now