I am trying to develop a Silverlight app which needs to populate a datagrid from PHP. I have the PHP working fine using the JSON format and Silverlight can read in the data but how can I add this data to a datagrid. I was looking at adding a new programmatically like you can in C# WF using DataRow but this doesn't seem to be available in Silverlight.
I have recently found out how I can do this by creating a class e.g. called Names that has get set methods inside it. Then use the following code to create the datasource for the datagrid
List<Names> source = new List<Names>();
foreach (JsonValue item in arrayJson)
{
string firstName = item["FirstName"].ToString().Replace('"', ' ').Trim();
string lastName = item["LastName"].ToString().Replace('"', ' ').Trim();
string age = item["Age"].ToString().Replace('"', ' ').Trim();
source.Add(new Names()
{
FirstName = firstName,
LastName = lastName,
Age = age
});
//MessageBox.Show("First Name: " + firstName + "\nLast Name: " + lastName + "\nAge: " + age, "Names", MessageBoxButton.OK);
}
tblGrid.ItemsSource = source;
However, when this code is used it creates a blank row for the number of records in the database no text. When I debug it and I look inside the source collection of items it shows all the correct values but the datagrid shows up blank rows.