簡體   English   中英

asp.net(C#)中網頁中的表格使用

[英]Table usage in the webpage in asp.net(C#)

  int numcells = 2;


          foreach (System.IO.FileInfo fi in fileQuery)
          {
              Label1.Text = fileList.Count().ToString();


                  TableRow r = new TableRow();
                  for (int i = 0; i < numcells; i++)
                  {
                      if (i.Equals("0"))
                      {


                          TableCell c = new TableCell();
                          c.Controls.Add(new LiteralControl(fi.Name.ToString()));
                          r.Cells.Add(c);


                      }
                      if (i.Equals("1"))
                      {


                          TableCell c = new TableCell();
                          c.Controls.Add(new LiteralControl(Server.MapPath(strheadlinesid).ToString() + fi.Name.ToString()));
                          r.Cells.Add(c);
                      }
                      Table1.Rows.Add(r);

              }

我嘗試使用上面的代碼在表中打印文件名及其路徑。
但由於某種原因,它沒有打印表格。
語法有沒有錯誤。
如果有人發現代碼中的錯誤,請告訴我。

i.Equals("0")i.Equals("1")不正確,應該是i.Equals(0)i.Equals(1)

這樣就解決了你的問題,Equals是用來判斷指定的object是否等於當前的object,而在這種情況下並不是因為“1”是字符串而1是Z157DB7DF530023575515D366E8Z6。

here查看有關 equals 的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM