Solved

Load Listbox from Multiple XML Files

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

736 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