问题描述
ViewState["rows"] = rows.ToString();
ViewState["cols"] = columns.ToString();
TableRow tr1 = new TableRow();
for (int i = 1; i <= rows; i++)
{
TableRow tRow = new TableRow();
Table1.Rows.Add(tRow);
for (int j = 1; j <= columns; j++)
{
TableCell tCell = new TableCell();
while(dr.read())
{
status=dr[0].tostring();
if(status!=0)
{
tCell.Style.Add("background-image", "removed(../images/A.jpg)");
}
else
{
tCell.Style.Add("background-image", "removed(../images/NA2.jpg)");
}
}
TextBox txt = new TextBox();
txt.ID = i + j.ToString();
txt.Text = "S" + i + j;
txt.Width = 35;
txt.BorderStyle = BorderStyle.None;
TextBox txt1 = new TextBox();
tCell.Text = "S" + j;
txt1.Text = "";
tCell.Controls.Add(txt);
tRow.Cells.Add(tCell);
}
}
Table1.Rows.Add(tr1);
上面的代码创建布局时不使用行号和列号.在这里使用两个for循环分别用于行和列.然后在检查status!= 0时再次添加一个图像,再添加另一个图像.
[edit]删除了SHOUTING,添加了缩进:与将其全部平放在屏幕左侧时相比,它更清晰,更易读吗? -OriginalGriff [/edit]
the above code create layout use no of row and no of column..here use two for loop for row and column..then again while check if status!=0 add one image else add another image.
[edit]SHOUTING removed, indentation added: See how much clearer it is, and easier to read than when you have it all flat to the left hand side of the screen? - OriginalGriff[/edit]
推荐答案
status=dr[0].tostring();
if(status!=0)
status
是字符串,在这种情况下与int的比较将导致错误,或者它是int,在这种情况下的赋值将导致错误.
当然,因为没有人会愚蠢到对所有变量都使用var
,只是为了避免不得不考虑它们在做什么!
即使是这样,测试仍然会失败,因为"0"不等于0 ...
Either status
is a string, in which case the comparison to an int will cause an error, or it is an int, in which case the assignment will cause an error.
Because of course, nobody would be stupid enough to use var
for all variables just to prevent having to think about what they were doing!
Even if they were, the test would still fail, because "0" is not equal to 0...
这篇关于有人可以验证我的代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!