I would like get an Array of objects and get a value based on the key.
Something like this javascript:
PageMethods.GetProducts(function(results) {
var productName = results[0].name;
});
I’ve tried this in code behind, but I get an array of arrays in the results:
VB
<WebMethod()>
Public Shared Function GetProducts() As ArrayList
Dim products As New ArrayList
Dim prAdptr As New DataSet1TableAdapters.ProductsTableAdapter
Dim prTbl As DataSet1.ProductsDataTable = prAdptr.GetData
Dim prRow As DataSet1.ProductsRow
For Each prRow In prTbl
Dim product As New Collection
product.Add(prRow.ProductID, "id")
product.Add(prRow.ProductName, "name")
products.Add(product)
Next
Return products
End Function
c#
[WebMethod()]
public static ArrayList GetProducts()
{
ArrayList products = new ArrayList();
DataSet1TableAdapters.ProductsTableAdapter prAdptr = new DataSet1TableAdapters.ProductsTableAdapter();
DataSet1.ProductsDataTable prTbl = prAdptr.GetData;
DataSet1.ProductsRow prRow = default(DataSet1.ProductsRow);
foreach ( prRow in prTbl) {
Collection product = new Collection();
product.Add(prRow.ProductID, "id");
product.Add(prRow.ProductName, "name");
products.Add(product);
}
return products;
}
Therefore I can’t get value based on a key.
I know i can reference the position of the value like so:
results[0][0];
but this is not ideal.
Any help would be appreciated.
You can use
Anonymous Typeshttp://msdn.microsoft.com/en-us/library/bb397696.aspx