How to access the current ItemType Item value from OnItemDataBound method of ListView?

拥有回忆 提交于 2019-12-11 09:27:25

问题


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:


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.
    ...
 }


来源:https://stackoverflow.com/questions/29733761/how-to-access-the-current-itemtype-item-value-from-onitemdatabound-method-of-lis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!