I have a web service and in the code below I loop through a collection of items. These items are desplayed in an xml like fashion (see example below). However I would like to display them in table like fashion. I thought of using the datatable to insert the items in there and then redisplay them.
585344
585344 Title Issue 1
585344 Number 140024
585344 State In progress
585350
585350 Title Issue 2
585350 Number 140026
585350 State Classification
How can I display them like this:
ID | Title | Number | State
585344 issue 1 140024 In progress
static void Main(string[] args)
{
ABWebService webSvc = new ABWebService();
GetObjectListData gold = new GetObjectListData();
gold.folderPath = "01. ITSM - Service Operation";
gold.RequiredField = new RequiredField[3];
gold.RequiredField[0] = new RequiredField {Value = "Title"};
gold.RequiredField[1] = new RequiredField {Value = "Number"};
gold.RequiredField[2] = new RequiredField {Value = "State"};
try
{
GetObjectListResult golr = webSvc.GetObjectList(gold);
List<NewsTracker> list = new List<NewsTracker>();
if (golr.success)
{
ObjectData[] myObjects = golr.Object;
for (int i = 0; i < myObjects.Length; i++)
{
Console.WriteLine(myObjects[i].id);
foreach (object myItem in myObjects[i].Items)
{
string field1 = string.Empty;
string val1 = string.Empty;
int val2 = 0;
string field2 = string.Empty;
StringVal item = myItem as StringVal;
if (item != null)
{
field1 = item.name;
val1 = item.Value;
Console.WriteLine("\t" + myObjects[i].id + " " + field1 + " " + val1);
}
LongIntVal val = myItem as LongIntVal;
if (val != null)
{
field2 = val.name;
val2 = val.Value;
Console.WriteLine("\t" + myObjects[i].id + " " + field2 + " " + val2);
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
EDIT 1:
can you tell me how can I add them in a generic list like this: list.Add(new NewsTracker(title,number,state));
so that I can loop through and do other things with the list?