Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4015934
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:40:44+00:00 2026-05-20T09:40:44+00:00

I have a ListView that displays comments for an article. Each comments has a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:40:45+00:00Added an answer on May 20, 2026 at 9:40 am

    Specify DataKeyNames attribute on the ListView markup and then get the DataKey in the button click event

    <asp:ListView runat="server" ID="myListView" DataKeyNames="CommentId" ...
    

    and in button click event, you can get the id

    (int)myListView.DataKeys[itemIndex]["CommentId"]
    

    or get commentId in fourth ListItem

    int commentId = (int)myListView.DataKyes[3]["CommentId"];
    

    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

    <asp:ListView onitemdatabound="myListView_ItemDataBound" runat="server" ID="myListView" ...
    
    protected void myListView_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListViewDataItem dataItem = (ListViewDataItem)e.Item;
            int commentId = (int)DataBinder.Eval(dataItem, "CommentId");
    
            // get author id based on comment id
    
            // or if you have auther id within the datasource
            // by which you are binding the listview then
    
            int ID_Author = (int)DataBinder.Eval(dataItem, "ID_Author");
    
            // get a reference to the delete button in the item
            // for instance you may do by this
            Control delete_button = e.Item.FindControl("deleteButtonId");
    
            // will hide if the author id don't match with the session id
            delete_button.Visible = ID_Author.Equals((int)Session["loggedin_userId"]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView on a page that displays a list of widgets. When
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have a listview that is binded to a ThreadSafeObservableCollection. The background of each
I have the following problem: I have two models: Article and Comment, in Comments,
I have an Activity that displays comments. The comments themselves have a layout, so
In one of my Activities I have a ListView that displays a list of
I have a ListView-like control that displays a list of items of various heights.
I have a ListView that displays error to the user. Part of it also
I have a ListView that displays sales orders, and groups them by status. In
I have a listview that displays entries for a given date. There are buttons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.