To expand on MZetko's answer, here's a method you can use with jQuery and Json.Net.
First, you'll need to set up a way to send the js array to your c# code. You can use something like this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var items = [["Q458", "", "100", "85"], ["Q459", "TS", "90", "65"], ["Q460", "", "80", "15"]];
sendToDb(items);
function sendToDb(inArr) {
var inString = JSON.stringify(inArr);
$.ajax({
url: "/Handlers/some-generic-handler.ashx",
dataType: 'json',
type: 'post',
data: { myVar: inString },
success: function (data) {
if (data.success == true) {
alert("Here's the first element in the array: " + data.firstElement)
alert(data.message);
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
</script>
Now, you'll need to build a handler that will answer the ajax request. This page will use Json.Net. The code will look something like this:
public class some_generic_handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string myVar = "";
if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.Form["myVar"])) { myVar = System.Web.HttpContext.Current.Request.Form["myVar"].Trim(); }
var myArr = JsonConvert.DeserializeObject<List<List<string>>>(myVar);
string firstElement = myArr[0][0];
string response = String.Format(@"{{ ""success"" : true, ""message"" : ""Cool! We're done."", ""firstElement"" : ""{0}"" }}", firstElement);
context.Response.ContentType = "application/json";
context.Response.Write(response);
}
public bool IsReusable
{
get
{
return false;
}
}
}
Be sure to install Json.Net by PM> Install-Package Newtonsoft.Json, and then include the following reference:
using Newtonsoft.Json;
This demo will convert the js array to a string, send it to your handler page, the handler page will deserialize that string to a c# array, send back the first element in the array to the initial page, and then the initial page will alert the first element. In your application, you would use the handler page to insert data into your db table.