Solved

Datatable row deletion in Gridview

Posted on 2007-03-22
5
440 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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now