我有一個C#代碼隱藏過程,它從數據庫中的幾個字段中讀取值,並將它們放入它自己的1維數組中。現在我需要將這些值傳遞給客戶端,以便我可以在熱敏打印機上打印它們。
在我的代碼隱藏我:從代碼背後的代碼傳遞數組到javascript
Public String[] PayType = new string[DetailLines];
Public String[] PayQuantity = new string[DetailLines];
Public String[] PayAmount = new string[DetailLines]'
Public String Location;
Protected Void PrintReceipt()
*Miscellaneous code down to this point not shown.*
**DetailLines comes from record count**
Location = "CA";
PayType = new string[DetailLines];
PayQuantity = new string[DetailLines];
PayAmount = new string[DetailLines]'
foreach (DataRow row in dtPOSdetail.Rows)
{
PayType[LineNumber] = row["fldDescription"].ToString();
PayQuantity[LineNumber] = row["fldQuantity"].ToString();
PayAmount[LineNumber] = string.Format("{0:C}",
Decimal.Parse(row["fldAmount"].ToString()));
LineNumber++;
}
在我的JavaScript,我有:
var getLocation = '<%= Location %>'
var getPayType = '<%= PayType %>'
var getPayQuantity = '<%= PayQuntity %>'
var getAmount = '<%= PayAmount %>'
我希望能夠通過這三個數組做循環在我的打印機的設置來建立線項目。
request += builder.createTextElement({ data: "Location: " + GetLocation + "\\n" });
for (int i = 0; i < PayType.Length; i++)
{
request += builder.createTextElement({ data: PayType[i] + "\\x9" + PayQuantity[i] + "\\x9" + " " + PayAmount[i] + "\\n"});
}
我可以打印出來的位置,但每個數組的值顯示爲'System.String []。我已閱讀的大多數主題都令人困惑,顯示數組被加載爲'var myarray(「蘋果」,「橙子」,「桃子」)。我也看到了關於序列化數組的主題,但是這並不明確。 任何如何完成我所展示的例子將不勝感激。 感謝 查爾斯
謝謝!這正是我期待的。希望我把事情做好,你的簡潔答案可以幫助別人。 – Charles