Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to delete a row from gridview using a checkbox. I m not using any database ..how to delete a blank row in gridview
Posted

Deleting multiple Rows in GridView using Checkbox[^] provides an easy way to help you get started.
This[^] should be a help for you as well.
http://csharpdotnetfreak.blogspot.com/2009/04/delete-multiple-rows-gridview-checkbox.html[^] offers a fairly simple exmaple too.
 
Share this answer
 
this is the code i have used in one of my page. hope this helps.
I have used list arrays and sessions for doing this. u can use viewstate also if there is no page navigation.

DiabeticFields objDiabeticFields = new DiabeticFields();
List<DiabeticFields> diabList = new List<DiabeticFields>();

I have used one button cmdDelete. After clicking on this button the following event will be fired


C#
protected void cmdDelete_Click(object sender, EventArgs e)
       {
          diabList = (List<DiabeticFields>)(Session["DiabObject"]);
               CheckBox chk = new CheckBox();
               foreach (GridViewRow gvr in grdDocOrders.Rows)
               {
                   chk = (CheckBox)(gvr.Cells[0].FindControl("chkSelect"));
                   if (chk.Checked == true)
                   {
                       diabList.RemoveAt(gvr.RowIndex);
                   }
                   Session["DiabObject"] = diabList;
                   if (diabList != null)
                   {
                       grdDocOrders.DataSource = diabList;
                       grdDocOrders.DataBind();
                   }
                   else
                   {
                       emptyGridFix();
                   }
               }
          }


the DiabObject contains all the rows of the gridview.There is no need to present these rows in database..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900