How to access the current ItemType Item value from

2019-08-07 01:18发布

In aspx page:

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

Code behind:

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

If I have this ListView where in ItemType="Post"; Post is a database table. How to access the current value of Item (which stands for the current record from thePost table) in the code behind method ListViewPosts_ItemDataBound

1条回答
Evening l夕情丶
2楼-- · 2019-08-07 01:45

Try this:

Please note, Post should be DataRow if Post is the table.

protected void ListViewPosts_ItemDataBound(object sender, ListViewItemEventArgs e)
{
   ...
   DataRow p = (DataRow)e.Item.DataItem; //where Item stands for the current Post record in ListView.
    ...
 }
查看更多
登录 后发表回答