Im trying to set an array in Javascript
, and then give it values from the DataTable
in the code behind like that :
我试图在Javascript中设置一个数组,然后在后面的代码中从DataTable中给它值,如下所示:
for (var i = 0; i < '<%=dt_questionVideo.Rows.Count - 1 %>'; i++) {
videoQarray[i] = '<%=Convert.ToInt32(dt_questionVideo.Rows['+i+'][0]) %>';
}
Im getting an error
我得到一个错误
Too many characters in character literal
字符文字中的字符太多
how can I manuover this one ?
我该如何制作这个呢?
1 个解决方案
#1
5
You can't really do it that way. If you need a javascript array like that, you're going to have to do something like this in the code behind:
你不能那样做。如果你需要像这样的javascript数组,你将不得不在后面的代码中做这样的事情:
int[] videoQarray = new int[dt_questionVideo.Rows.Count - 1];
for (var i = 0; i < dt_questionVideo.Rows.Count - 1; i++) {
videoQarray[i] = Convert.ToInt32(dt_questionVideo.Rows[i][0]);
}
string createArrayScript = string.Format("var videoQarray = [{0}];", string.Join(",", videoQarray));
Page.ClientScript.RegisterStartupScript(this.GetType(), "registerVideoQArray", createArrayScript, true);
#1
5
You can't really do it that way. If you need a javascript array like that, you're going to have to do something like this in the code behind:
你不能那样做。如果你需要像这样的javascript数组,你将不得不在后面的代码中做这样的事情:
int[] videoQarray = new int[dt_questionVideo.Rows.Count - 1];
for (var i = 0; i < dt_questionVideo.Rows.Count - 1; i++) {
videoQarray[i] = Convert.ToInt32(dt_questionVideo.Rows[i][0]);
}
string createArrayScript = string.Format("var videoQarray = [{0}];", string.Join(",", videoQarray));
Page.ClientScript.RegisterStartupScript(this.GetType(), "registerVideoQArray", createArrayScript, true);