Asp.net ListView运行总计

Asp.net ListView运行总计,asp.net,listview,count,Asp.net,Listview,Count,我有一个listview,想计算一个运行的值的总数。 绑定到listview的每个数据项都有一个“金额”。 在ListView1_ItemDataBound上,我想获取数据项的“amount”值,但找不到如何访问该项 我想这有点类似,只是我想要一个连续的总数,而不是最后的总数 您应该能够在ListViewItem中的DataItem中找到该项。一些示例代码可能如下所示: public int ListViewTotal { get; set; } protected void MyLis

我有一个listview,想计算一个运行的值的总数。 绑定到listview的每个数据项都有一个“金额”。 在ListView1_ItemDataBound上,我想获取数据项的“amount”值,但找不到如何访问该项

我想这有点类似,只是我想要一个连续的总数,而不是最后的总数


您应该能够在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();
    }
  }

希望这能帮助您找到正确的方向。

您应该能够在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();
    }
  }

希望这能为您指明正确的方向。

您是如何获得数据项的?“数据项”来自哪里?谢谢!我让它工作了。((ListViewDataItem)e.Item);如何获取数据项?“数据项”来自哪里?谢谢!我让它工作了。((ListViewDataItem)e.Item);