【问题标题】:run through an itemArray [duplicate]遍历 itemArray [重复]
【发布时间】:2014-12-08 09:48:12
【问题描述】:

因此创建一个数据表并遍历其中的所有行。问题是 DataRow r 包含一个 itemArray[] 我也需要运行。

DataTable currentAttribs = //results for datatable;

foreach (DataRow r in currentAttribs.Rows)
          {
            //foreach itemArray[] in r do the following
            {
                  tableRow = "<TR><TD>" + r[0].ToString() + "</TD></TR>";
                  Literal lc = new Literal();
                  lc.Text = tableRow;
                  divFeatureInfo.Controls.Add(lc);
            {
          }

不确定在 'r' 中遍历 itemArray 的语法...谢谢

【问题讨论】:

    标签: c# asp.net asp.net-mvc


    【解决方案1】:

    ItemArray 是 Object[]:

    foreach (DataRow r in currentAttribs.Rows)
    {
        foreach (Object obj in r.ItemArray)
        {
              string tableRow = string.Format("<TR><TD>{0}</TD></TR>", r[0]);
              Literal lc = new Literal();
              lc.Text = tableRow;
              divFeatureInfo.Controls.Add(lc);
              // do whatever you need to do with obj
        }
    }
    

    【讨论】:

    • 实际上我在写 Q..duh 的时候在想我应该尝试一下..谢谢你的回复,虽然欢呼蒂姆
    • - 维护世界和平!
    猜你喜欢
    • 2010-11-07
    • 2019-11-21
    • 2016-09-07
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 2012-04-08
    • 2014-07-06
    相关资源
    最近更新 更多