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

  • SEARCH
  • Home
  • 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 6081409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:10:20+00:00 2026-05-23T11:10:20+00:00

I am currently attempting to delete a row (or rows) from a listview via

  • 0

I am currently attempting to delete a row (or rows) from a listview via a checkbox. The code I have is below.. I have used the same on a similar area of the site however this one doesn’t seem to work. The check box is ticked, the delete button is pressed and it just reloads the page without deleting.

Page Load

protected void Page_Load(object sender, EventArgs e)
{
    DSTableAdapters.contact_messagesTableAdapter cmta = new DSTableAdapters.contact_messagesTableAdapter();
    DSTableAdapters.messagesTableAdapter mta = new DSTableAdapters.messagesTableAdapter();
    DSTableAdapters.user_messagesTableAdapter umta = new DSTableAdapters.user_messagesTableAdapter();

    DataTable cMessageTable = cmta.GetAll();
    DataTable ownerMessagesTable = umta.GetMessages("owner");
    DataTable clientMessagesTable = umta.GetMessages("user");

    lvContact.DataSource = cMessageTable;
    lvContact.DataBind();

    lvClientMessages.DataSource = clientMessagesTable;
    lvClientMessages.DataBind();

    lvOwnerMessages.DataSource = ownerMessagesTable;
    lvOwnerMessages.DataBind();
}

Markup:

   <asp:ListView ID="lvContact" runat="server" DataKeyNames="contact_id">
      <LayoutTemplate>
        <table id="itemPlaceHolderContainer">
          <tr>
            <th>Message ID</th>
            <th>Email Address</th>
            <th>Message</th>
            <th>Date</th>
          </tr>
          <tr runat="server" id="itemPlaceHolder"></tr>
        </table>
      </LayoutTemplate>
      <ItemTemplate>
        <tr>
          <td>
            <asp:CheckBox ID="chkContactID" runat="server" AutoPostBack="false" />
          </td>
          <td>
            <asp:Label ID="lblContactEmail" runat="server" Text='<%#Eval("email") %>' />
          </td>
          <td>
            <asp:Label ID="lblContactMessage" runat="server" Text='<%#Eval("message") %>' />
          </td>
          <td>
            <asp:Label ID="lblContactDate" runat="server" Text='<%#Eval("date") %>' />
          </td>
        </tr>
      </ItemTemplate>
    </asp:ListView>
    <asp:Button ID="btnContactDelete" runat="server" 
    Text="Delete Selected Messages" onclick="btnContactDelete_Click" />

Code-behind:

protected void btnContactDelete_Click(object sender, EventArgs e)
{
    // Loop through each row to find checked boxes
    for (int i = 0; i < lvContact.Items.Count; i++)
    {
        ListViewDataItem items = lvContact.Items[i];
        int iContactID = Convert.ToInt16(lvContact.DataKeys[items.DataItemIndex]["contact_id"]);
        CheckBox chkBox = (CheckBox)items.FindControl("chkContactID");
        if (chkBox.Checked == true)
        {
            Response.Write(iContactID);
            // If selected to be deleted
            DSTableAdapters.contact_messagesTableAdapter cmta = new DSTableAdapters.contact_messagesTableAdapter();
            cmta.DeleteMessage(iContactID);
        }
    }
    lvContact.DataBind();
}
  • 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-23T11:10:20+00:00Added an answer on May 23, 2026 at 11:10 am

    Do you populate the ListView in your page load, you might need to have

    if (!IsPostBack)
    {
         //Fill ListView
    }
    

    I think when the webpage does a post back you loosing the checked checkboxes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently attempting to implement a custom gridview interface to display data from
I'm currently attempting to code one for part of a college project - binary/hex
I am currently attempting to follow along with section 10.38 from RoR Tutorial. All
Currently attempting to get some code to compile using Lejos for the Lego NXT
I'm currently attempting to retrieve a list of objects from my database using jQuery.
I am currently attempting to move a JFrame (the same way you would by
I'm currently attempting to track down the source of heap corruption in our code
Currently I have some code deleting some temporary files created by my program: #
I'm currently using a HttpResponse to download files from my Server. I already have
I'm currently attempting to print a document from WPF. I'm using the web browser

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.