?
Solved

Load Listbox from Multiple XML Files

Posted on 2007-04-11
4
Medium Priority
?
730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Accepted Solution

by:
asp_lha earned 750 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 750 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

719 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