[英]C# Multidimensional array only printing first element
我正在嘗試將List
變量的內容填充為引導程序模式。 我的問題是代碼僅顯示List
變量的第一個元素。
這是我的代碼:
List<string[]> listStatus = new List<string[]>();
for (int i = 0; i < listStatus.Count; i++)
{
for (int j = 0; j < 2; j++)
{
string body = listStatus[i][j+1].ToString();
body = body + " - " + listStatus[i][j].ToString();
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "populateModal('" + body + "');", true);
}
}
ClientScript.RegisterStartupScript(this.GetType(), "Show", "showModal()", true);
附加代碼:
protected void btnSplunk_Click(object sender, EventArgs e)
{
string sp_ip = "172.16.159.94";
int sp_port = 22;
string status = CheckCon(sp_ip, sp_port, lblSplunkUpdate);
listStatus.Add(new string[] { status, sp_ip });
}
protected void btnRandom_Click(object sender, EventArgs e)
{
string ran_ip = "134.32.233.21";
int ran_port = 801;
string status = CheckCon(ran_ip, ran_port, lblRnadomUpdate);
listStatus.Add(new string[] { status, ran_ip });
}
有人可以強調我做錯了什么,並指出正確的方向嗎?
因此,我重組了代碼邏輯,它開始工作了。 我沒有使用多維數組,而是使用了連接字符串。 解決方法,但效果很好
List<string> listStatus = new List<string>();
string body = "";
for (int i = 0; i < listStatus.Count; i++)
{
string var = listStatus[i].ToString();
body = body + var + "</br>";
}
Response.Write(body + "</br>");
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "openModal('" + body + "');", true);
ClientScript.RegisterStartupScript(this.GetType(), "Show", "showModal()", true);
JavaScript:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
function openModal(body) {
$("#exampleModalCenter .modal-body").html(body);
}
function showModal() {
$("#exampleModalCenter").modal("show");
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.