Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Datatable row deletion in Gridview

Posted on 2007-03-22
5
Medium Priority
?
451 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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…

721 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