我在c#中创建了一个5x10矩阵。现在,我想将这些值检索到ASP中的5x10表中。只有两个可能的值“可用”和“不可用”。如果值为1,则表格单元格背景应显示为绿色。如果值为0,则表格单元格背景应显示为红色。我怎样才能做到这一点?以下是我到目前为止编写的用于将值从DropDownList插入矩阵的代码
protected void Button1_Click(object sender, EventArgs e)
{
String[][] matrix=new String[5][];
for(int i=0;i<5;i++)
{
matrix[i]=new String[10];
}
int q=1;
for (int i = 0; i <= 4; i++)
{
for (int j = 0; j <= 9; j++)
{
DropDownList tb = this.FindControl("DropDownList" + q) as DropDownList;
matrix[i][j] = tb.SelectedItem.Text;
q++;
}
}
为了将这些值重新检索到表中,如果值是“ Available”,如何将单元格背景显示为绿色,如果值是“ Unavailable”,则如何将单元格背景显示为红色,我没有任何想法。
您可以尝试以下方法:
for(int rows=0;rows<Table1.Rows.Count;rows++)
{
for (int cols = 0; cols < Table1.Rows[rows].Cells.Count; cols++)
{
if (Convert.ToInt32(Table1.Rows[rows].Cells[cols].Text.ToString()) == 1)
{
Table1.Rows[rows].Cells[cols].BackColor = Color.Green;
}
else if (Convert.ToInt32(Table1.Rows[rows].Cells[cols].Text.ToString()) == 0)
{
Table1.Rows[rows].Cells[cols].BackColor = Color.Red;
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句