In jquery/javascript the array has following structure. And I am able to fetch the data using, data[cartIndex].rows[i].
//cartIndex is anything from 0 to 10;
//row is like [name, quantity, balance, remarks]
for (var i=0; i < data[cartIndex].length; i++) {
var row = data[cartIndex].rows[i];
alert(row.name, row.quantity, row.balance);
}
I used both a list and an array to populate data in C# and serialized it.
UPDATED CODE:
var arrList = new List<object>();
string x = string.Empty;
int i = table.Rows.Count;
foreach (DataRow row in table.Rows)
{
string name = row[0].ToString();
string quantity = row[1].ToString();
string balance = row[2].ToString();
string remove = "X";
arrList.Add(new Wrapper { rows = new [] { name, quantity, balance, remove }});
}
var maList = new List<object>();
maList.Add(arrList);
return (new JavaScriptSerializer()).Serialize(maList);
But somehow it's not in the correct column row format in javascript.
data = [
[[name, quantity, balance, remarks],
[name, quantity, balance, remarks],
[name, quantity, balance, remarks]
],
[[name, quantity, balance, remarks],
[name, quantity, balance, remarks],
[name, quantity, balance, remarks]
]
]
With this, I am not able to access the array rows like this:
var row = data[cartIndex].rows[i];
//row.name gives name, row.quantity gives quantity and so on
This structure should also allow to push a row into the array.
data[cartIndex].length++;
data[cartIndex].rows.push({name: name,
quantity: quantity, balance: blance});
How can I structure the c# array to be accessed via row indices?