|
-
Nov 13th, 2004, 05:01 PM
#1
Thread Starter
Hyperactive Member
Fill DataList with a String[,]
My question is very simple.
How do I fill a datalist with a 2D String array?
My array is of type String [x,2]
I need to know this because I need to display a list of attributes and their value. Those attributes are fields like "name", "age", "country".
[x,0] always contains the attributename and
[x,1] always contains the value
Thank you in advanced.
I hope the question is clear.
Last edited by BramVandenbon; Nov 13th, 2004 at 05:07 PM.
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Nov 14th, 2004, 08:17 AM
#2
Thread Starter
Hyperactive Member
Code:
DataTable dt = new DataTable();
DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("Attribute", typeof(String)));
dt.Columns.Add(new DataColumn("Value", typeof(String)));
// Populate the table with values.
for (int i = 0; i < attributes.Length; i++)
{
dr = dt.NewRow();
dr[0] = attributes[i,0];//attributename
dr[1] = attributes[i,1];//attributevalue
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
dtlmydatalist.DataSource = dv;
dtlmydatalist.DataBind();
I found the answer, I am converting it first to a DataView and after that I am adding it (allthough according to the prototype of the datasource property it should be able to accept an array too, but that just doesnt seem to work, maybe because my array is a 2d array).
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|