Solved

Datatable row deletion in Gridview

Posted on 2007-03-22
5
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

729 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