Solved

Load Listbox from Multiple XML Files

Posted on 2007-04-11
4
726 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 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