again i come up with new tricks of GridView in that you can Delete / Update / Move
seleted records from Gridview, take a Example of Gmail inbox it shows total number of mail on your "Inbox" in that have a option like Delete , move to another folder , Delete all , and so on, same feature you can add in your Gridview
look at the Below Example hope u like it .
<asp:GridView ID="GridView1" datakeyname="Mailid" runat="server"
<asp:CheckBox ID="CheckAll" runat="server" onclick="return check(this);"/>
<asp:Label ID="MailID" runat="Server"
Text='<%# DataBinder.Eval (Container.DataItem, "MailID") %>'
<asp:CheckBox ID="DeleteRec" runat="server" onclick="return check(this);"/>
<asp:SqlDataSource ID="Sqldatasource1" runat="server"
SelectCommand="Select MailId,MailBody,Date,To,From from MailInbox"
2. we have Button Which act as a Delete /Move / Upadate Operation.
<asp:Button ID="Button1" OnClientClick="return confirmMsg(this.form)"
Text="Move" OnClick="Button1_Click" runat="server" />
var MailChecked = Val.checked;
var MailId = Val.id;
var frm = document.forms;
// Loop through all Records in GridView
for (i = 0; i < frm.length; i++)
// Also Check if the Heder Template Option get Checked or Not
if (this != null)
if (MailId.indexOf('CheckAll') != - 1)
// Now check if Header template checkbox is Checked so it will Delete/Move all the
// Then select or deselect datagrid checkboxes
frm.elements[i].checked = true;
frm.elements[i].checked = false;
else if (MailId.indexOf('DeleteRec') != - 1)
// Check if any of the checkboxes are not checked,
and then uncheck top select all checkbox
if (frm.elements[i].checked == false)
frm.elements.checked = false;
4.Now we can Configure Move/Delete Configration Message .
// Now Again gone through the All the Gridview Elements
for (i = 0; i < frm.length; i++)
// Check for checkboxes only
if (frm.elements[i].name.indexOf("DeleteRec") != - 1)
// Show Alert message to End user to Really want to Delete / Move .
return confirm('Do you really want to Move/Delete Seleted Item')
5. on CodeBehind Button1_Click Event Perform the Action.
protected void Button1_Click(object sender, EventArgs e)
bool chkBox = false;
string GvID = "";
//Check each row in GridView for Select ot not.
foreach (GridViewRow gv in GridView1.Rows)
CheckBox MoveSelectedCheck = (CheckBox)gv.FindControl("DeleteRec");
chkBox = true;
// add the Seleted item with (;) so it can delete that or Move that
GvID += ((Label)gv.FindControl("MailID")).Text.ToString() + ",";
SqlConnection conn = // Define Connection String.
// Suppose Folder name or Lable name is (OldMail)
string MoveRec = "Update MailBox set Label ='+ OldMail +' where MailID IN (" +
GvID.Substring(0, GvID.LastIndexOf(",")) + ")";
SqlCommand cmd = new SqlCommand(MoveRec, conn);
catch (SqlException err)
Response.Write("Error at :-"+err);
Like this you can Perform Deletion or Updataion or Moving Oepration ,
if you are Deleting Records then its very easy you can use Delete query
if it is Updation use Update query .But in the case of Moving just like (Gmail inbox ) you have one option you can set the Status of that Seleted Mail as (Name of Folder) just like (Label part in Gmail )
and when you get click on that lable do code such that, Check if the any records from Gridview are Marked as (Lable name ) and you query according to same.
plz comment on it , if u have any query .......