【问题标题】:ListView Running totalListView 运行总计
【发布时间】:2010-01-15 14:44:39
【问题描述】:

我有一个列表视图,想计算一个运行总和。 我绑定到列表视图的每个数据项都有一个“数量”。 在 ListView1_ItemDataBound 上,我想获取数据项的“数量”值,但我找不到如何访问该项目。

这有点相似,我想,只是我想要一个总和,而不是最后的总数。

Displaying totals in the ListView LayoutTemplate

【问题讨论】:

    标签: asp.net listview count


    【解决方案1】:

    您应该能够在 ListViewItem 内的 DataItem 中找到该项目。一些示例代码可能如下所示:

    public int ListViewTotal
    {
     get; set;
    }
    
      protected void MyListView_ItemDataBound(object sender, ListViewItemEventArgs e)
      {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
          // Retrieve the underlying data item. In this example
          // the underlying data item is a DataRowView object.        
          DataRowView rowView = (DataRowView)dataItem.DataItem;
    
          ListViewTotal += rowView["amount"];
    
          //Set text of listview control to new total:
          Label lbl = (Label)e.Item.FindControl("myAmountLabel");
          lbl.Text = ListViewTotal.ToString();
        }
      }
    

    希望能帮助您指明正确的方向。

    【讨论】:

    • 你是如何获取数据项的? “dataItem”从何而来?
    • 谢谢!我让它工作了。 ((ListViewDataItem)e.Item).DataItem;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 2012-07-03
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多