有人可以验证我的代码吗? [英] Could any one verify my code?

查看:74
本文介绍了有人可以验证我的代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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]

推荐答案

您需要仔细研究一下自己要做什么,然后再回去做一些基本的事情.

首先,看一下缩进后一切都变得容易多了吗?

其次,随便一眼就说这不会编译".
You need to take a long, hard look at what you are trying to do, and then go back and do some basic stuff.

Firstly, see how much easier everything is when it is indented?

Secondly, a casual glance says "This won''t compile".
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...


这篇关于有人可以验证我的代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆