Solved

Datatable row deletion in Gridview

Posted on 2007-03-22
5
442 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
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…

932 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

13 Experts available now in Live!

Get 1:1 Help Now