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 7633671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:57:01+00:00 2026-05-31T06:57:01+00:00

I have a gridview and binding the records in it from a list.I need

  • 0

I have a gridview and binding the records in it from a list.I need to delete multiple rows from the list

int deleled=0;
foreach(gridviewrow row in gridview1.rows)
{
   checkbox chkSelectedItem=(checkbox)row.findcontrol("chkSelectedItem");
   if(chkSelectedItem.checked)
   {
      int id=(int)gridview1.DataKeys[row.RowIndex].Values["Id"];
      Person person=new Person();
      person.Id=id;

      deleted+=person.Delete(user);

      gridview1.DeleteRow(row.rowindex);
    }
}

gridview1.datasource=persons;
gridview1.databind();

here I have seperate class for deleting the user…thats working fine, I need to delete the selected records in database as well as gridview and I have to display the other records in gridview…..the problem is I’ve records for many users in Persons table, I need to display particular persons details in gridview…

the deleting records working fine,no problem in that, but when I delete the rows in gridview it skips the indexes…for example if select records 1,3,5,7,9 in the total of 10 records, when the control comes for the 1st record at 0th index, after the execution of
gridview1.DeleteRow(row.rowindex);
the 2nd record(at 1st index) fills the 0th index, and when the control comes to get the id, it gets only the 4th record instead of 3rd record….I even tried to get the selected indexes using list and tried deleting the records using their indexes in that list, that also showing the same problem, I can understand the control flow….but I dunno how to fix this….can anyone help me out

  • 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-31T06:57:02+00:00Added an answer on May 31, 2026 at 6:57 am

    If your Persons list not very large, one way is to first unbind GridView’s data source, delete Person from Persons list and don’t delete GridView’s rows yourself then bind that list to its data source.

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

Sidebar

Related Questions

I'm binding a gridview dynamically from a table in my database I have called
I have a List (Of MyObject) binding to a GridView in the Page_Load event.
I have a list binding on a gridview. HistoryGrid.DataSource = objGrid; HistoryGrid.DataBind(); AllowSorting=true AllowPaging=True
I have a gridview where i am using a binding list for binding. In
I have the GridView below. I am binding to a custom datasource in the
I have problems binding both a telerik RadGrid and a plain vanilla ASP.NET GridView
We have an app that uses simple one way binding with a GridView to
I have GridView which I can select a row. I then have a button
Have a gridview control which will show X amount of rows. I want to
I have some methods in my BLL that fetch some records from database and

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.