I have a ListView that displays comments for an article.
Each comments has a button that, when clicked, deletes that comment provided that the logged person is the comment’s owner or an administrator.
I need a way of storing comment’s ID in the ListView somehow and then I need to check if the ID of the comment’s author is the same as the ID of the logged user (which is stored in the Session) and then, if they match, display the button that deletes the comment when clicked.
Please help.
Specify DataKeyNames attribute on the ListView markup and then get the DataKey in the button click event
and in button click event, you can get the id
or get commentId in fourth ListItem
Edit, as you mention your requirements further
You can access the current item being bind to list view in ItemDataBound event
Just add the ItemDataBound event attribute on ListView mark up, and do your logic within the event