Select And Delete Multiple Rows In Gridview Contro
Select And Delete Multiple Rows In Gridview Control
GridView Control allow to select only one row at a time but But a little logic is required to select more than one row or Multiple rows in GridView control. if we require to select Multiple row and delete them in a single click than we can do this by writing a little code.
In my example I am using CheckBox control of asp.net . A CheckBox control is added in every row of grid view ( using TemplateField) and any GridView row can be selected by selecting CheckBox control of that particular row.
Following sqlserver table (tbemp) is used in the example
Here is code for .aspx page
Code for .cs file (Replace the Page_Load event with following code)
In LinkButton3_Click event first we loop through each row of gridview and and then tested if they are selected (CheckBox checked) or not, the ‘Emp ID’ of each selected row is concatinated in a string variable named ‘d’ and passed as parameter in delete query “delete from tbemp where eno in("+d.ToString()+")"
No comments:
Post a Comment