我有一個DataTable,我從數據庫中獲得,我想在後面的代碼中創建一個2d數組(一旦我得到DataTable ..),然後將其作爲2d傳遞數組轉換爲Javascript。傳遞2d數組從代碼背後到javascript
這就是我試圖代碼:
int[,] videoQarray = new int[dt_questionVideo.Rows.Count,dt_questionVideo.Columns.Count ];
string[,] videoQarrayTitle = new string[dt_questionVideo.Rows.Count, dt_questionVideo.Columns.Count ];
for (var i = 0; i < dt_questionVideo.Rows.Count ; i++)
{
for (int j = 0; j < dt_questionVideo.Columns.Count; j++)
{
videoQarray[i,j] = Convert.ToInt32(dt_questionVideo.Rows[i][0]);
videoQarrayTitle[i,j] = dt_questionVideo.Rows[i][1].ToString();
}
}
string createArrayScript = string.Format("var videQarray = [{0}];", string.Join(",", videoQarray));
createArrayScript += string.Format("var videQarrayList = [{0}];", string.Join(",", videoQarrayTitle));
Page.ClientScript.RegisterStartupScript(this.GetType(), "registerVideoQArray", createArrayScript, true);
好,它說,videoQarray沒有定義瀏覽器控制檯.. 我不知道我該怎麼做正確..
nope。同樣的錯誤.. – thormayer 2012-08-10 21:06:41
謝謝!有效! – thormayer 2012-08-10 21:20:25