Solved

Load Listbox from Multiple XML Files

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

624 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