Click to See Complete Forum and Search --> : Datalist and itemtemplate


Endymion
January 2nd, 2003, 05:45 AM
Hi,
I am currently working on the display of an xml file by means of a datalist. What I need to accomplish is to add data items and their associated controls dynamically. So I need a method to determine runtime which fields my xml-file contains and add these fields to my datalist. Any ideas?

Or alternatively; does anyone know if one can display a datagrid in the following manner:

column1 : value1
column2 : value2
etc.

?

thx!

Leo Ayala
January 6th, 2003, 12:23 PM
The following code automatically fills a DataLIst control with data from an xml file;

DataSet ds = new DataSet();
ds.ReadXml("[path]xmlfile.xml");

myDataList.DataSource = ds;
myDataList.DataBind();

A DataSet also has Tables and Rows properties which you can use to examine each record and its fields. For example:

foreach(DataTable table in ds.Tables)
{
// for each row, print the values of each column
foreach(DataRow row in table.Rows)
foreach(DataColumn col in table.Columns)
{
// print column
}
}