在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
Post
的当前值(代表ListViewPosts_ItemDataBound
表中的当前记录)
答案 0 :(得分:0)
试试这个:
请注意,如果帖子是表格,帖子应为 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.
...
}