TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rahul Khanna
NA
236
0
How to delete selected rows from gridview datatable.
Nov 9 2014 10:08 AM
Hi all,
I am trying to delete selected rows from gridview in button click event.My code is not deleting the correct row, if I select first row its deleting the 2nd row and If I select 2nd row its deleting the 3rd row and so on.
Here is my code:
protected void btnRemoveUser_Click(object sender, EventArgs e)
{
DataTable yourDataTable = GetDataTable(Studentlist); //CheckBox chkbx;
foreach(GridViewRow oneRow in Studentlist.Rows)
{
CheckBox chkbx = (CheckBox)oneRow.FindControl("ckbxID");
for(int i = 0; i< yourDataTable.Rows.Count; i++)
{
if (chkbx.Checked == true)
{
yourDataTable.Rows.RemoveAt(i);
}
break;
}
}
Studentlist.DataSource = yourDataTable;
Studentlist.DataBind();
}
Note: Studentlist is the gridview ID.
Here, my purpose is to delete the selected rows from gridview so any alternate solution is also appreciated.
Reply
Answers (
2
)
login part creation
Best CMS