Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
My problem is that I have a grid view for displaying inbox content of internal messages which is binded to a datatable. When I check a particular row with the help of check box ,that row should removed from grid view plus from the database on DELETE Button Command located outside the Gridview .How to remove the particular row and all selected rows from grid view.
Thanks with Regards,
Naveen
Posted

In delete button click event
C#
foreach (GridViewRow gvrow in GridView1.Rows)
{
 //use findcontrol to get the check box.
 if(checkbox.checked)
 {
   // code to delete the checked rows from database.
 }
}


Try..
 
Share this answer
 
Comments
naveen.0nick 30-Mar-11 1:06am    
can u also tell me how to find the control for checked Id from gridview
m@dhu 30-Mar-11 1:34am    
CheckBox cb = (CheckBox)row.FindControl("chkBoxId");
chkBoxId is your check box id.
this is an example
try this

write Javascript function To store Productid (1|2|3|4) in this way
function Fn_JsOrders_GetCheckBoxList() {
            var jsVar_Orders_OrderId = "";
            var flag = false;

            // alert(document.aspnetForm.OrderId.length);
            var ctrls = document.getElementsByTagName("input");
            for (var i = 1; i < ctrls.length; i++) {
                if (ctrls[i].checked == true) {
                    //  alert(jsVar_Orders_OrderId);
                    jsVar_Orders_OrderId = jsVar_Orders_OrderId + ctrls[i].value + "|";
                }
            }
            if (jsVar_Orders_OrderId.length == 0) {
                alert("Please Select Atleast One item");
                flag = false;
            }
            else {
                document.getElementById("<%=hid.ClientID %>").value = jsVar_Orders_OrderId;
                var answer1 = confirm("Are You Sure You Want to Delete ?");
                if (answer1) {
                    flag = true;
                    document.aspnetForm.submit();
                }
                else {
                    flag = false;
                }
            }
            return flag;

        }

hid_Hospital_HospitalId.ClientID (Hiddenfield) declare hiddent field in ur aspx page


In code behid


on click on delete button

Id = (HiddenFieldvalue)

char[] separator = new char[] { '|' };
                string[] strProductId = ProductId.Split(separator);
                string[] strProductQuantity = ProductQuantity.Split(separator);
                for (int i = 0; i < strProductId.Length - 1; i++)
                {
                    int ProdId = Convert.ToInt32(strProductId[i]);

                    

                    Result = fn_Delete(ProdId);

                }
 
Share this answer
 
v2
Comments
pankajupadhyay29 30-Mar-11 0:58am    
code wraped in pre blocks
naveen.0nick 30-Mar-11 1:08am    
Mahen, i have just learned ASP.NET.
i am just at the beginner level, so i am really not getting how to apply your code. :(
naveen.0nick 30-Mar-11 1:10am    
ok i an trying now

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