Solved

Datatable row deletion in Gridview

Posted on 2007-03-22
5
445 Views
Last Modified: 2012-05-05
Hi,
 I have a gridview, which is binded to datatable. I too have a checkbox in each row in gridview. Now, i would like to delete the selected rows by selecting the checkbox in button click event. I have tried as follows.
           foreach (GridViewRow row in GridView1.Rows)
            {                
                bool ischecked = ((CheckBox)row.FindControl("chkDelete")).Checked;
                if (ischecked == true)
                {                    
                    row.Cells.Clear();
                }
            }    

 It worked fine.But, when i add a new row to gridview i see that the deleted rows are getting displayed back again. so, can anybody help me out to delete a row in datatable in gridview?
0
Comment
Question by:veradistech
5 Comments
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 18770017
add a bit column to ur data table

then that check box will automatically come

if not u can manually add that

then on row change event of the datatable u can do this
FTable.RowChanged += new DataRowChangeEventHandler(FTable_RowChanged);


private void FTable_RowChanged(object sender, DataRowChangeEventArgs e)
            {
                  if(Convert.ToBoolean(e.Row["CHK"]))
                  {
                        e.Row.Delete();
                  }
            }
0
 
LVL 11

Expert Comment

by:G0ggy
ID: 18770055
Am I wrong in thinking that there is no code in there to actually delete the row from the database, so when the control is re-bound the data will still appear?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 47
C#, asp.net MVC, sql server, LINQ 3 32
asp day pilot 3 21
tutorial for ebay api 3 36
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question