1

在 aspx 页面中:

<asp:ListView ID="ListViewPosts" ItemType="Post" 
SelectMethod="ListViewPosts_GetData" runat="server"
OnItemDataBound="ListViewPosts_ItemDataBound">
        ...
        ...
    </asp:ListView>

后面的代码:

protected void ListViewPosts_ItemDataBound(object sender, ListViewItemEventArgs e)
{
  ...
  Post p = Item; //where Item stands for the current Post record in ListView.
  ...
}

如果我有这个ListView在哪里ItemType="Post"Post是一个数据库表。如何在代码隐藏方法中访问Item(代表表中的当前记录)的当前值PostListViewPosts_ItemDataBound

4

1 回答 1

0

尝试这个:

请注意,如果Post是表格,则Post应该是DataRow 。

protected void ListViewPosts_ItemDataBound(object sender, ListViewItemEventArgs e)
{
   ...
   DataRow p = (DataRow)e.Item.DataItem; //where Item stands for the current Post record in ListView.
    ...
 }
于 2015-04-19T18:12:04.033 回答