Finishing an Online E-Mail System in ASP.NET 2.0 - Deleting Your Email
(Page 4 of 5 )
It's comparatively easy to delete email, which is accomplished in the DeleteBtn_Click event on the ViewMail.aspx page.
protected void DeleteBtn_Click(object sender,EventArgs e){
///create a new instance of class Mail
IMail mail = new Mail();
try {
foreach(GridViewRow row in MailView.Rows)
{ ///find your control
CheckBox checkMail = (CheckBox)row.FindControl("CheckMail");
if(checkMail != null)
{
if(checkMail.Checked == true)
{
///execute the requested operation on the database
mail.DeleteMail(Int32.Parse(MailView.DataKeys[row.RowIndex].Value.ToString()));
}
}
}
///rebind the data to the control
BindMailData(nFolderID);
}
catch(Exception ex)
{ ///jump to the page responsible for dealing exception
Response.Redirect("ErrorPage.aspx?ErrorMsg=" + ex.Message.Replace("<br>","").Replace("n","")
+ "&ErrorUrl=" + Request.Url.ToString().Replace("<br>","").Replace("n",""));
}
}
As is seen from above, we first find the ID value matching each e-mail to be deleted in the mail list control named MailView, and then invoke the DeleteMail method of the Mail object, which is finished through a typical for loop sentence. Here, remember that after deleting the selected e-mail, you have to rebind the data to MailView (i.e. refresh).
Next: Moving Your Email >>
More ASP.NET Articles
More By Xianzhong Zhu