示例#1
0
 protected void dgMsg_ItemCommand(object source, DataGridCommandEventArgs e)
 {
     if (e.CommandName == "del")
     {
         int msgId = Convert.ToInt32(e.CommandArgument);
         try
         {
             MsgBll.DeleteMsg(msgId);
             MessageBox.Alert("删除成功!", Page);
             BindData();
         }
         catch (Exception)
         {
             MessageBox.Alert("删除失败!", Page);
             /*throw;*/
         }
     }
 }
示例#2
0
        protected void btnDelSelect_Click(object sender, EventArgs e)
        {
            int selectNum = 0;

            for (int i = 0; i < dgMsg.Items.Count; i++)
            {
                CheckBox chk = dgMsg.Items[i].FindControl("chkSelect") as CheckBox;
                if (chk.Checked)
                {
                    selectNum++;
                }
            }
            if (selectNum == 0)
            {
                MessageBox.Alert("请选择要删除的项!", Page);
            }
            else
            {
                for (int i = 0; i < dgMsg.Items.Count; i++)
                {
                    CheckBox chk = dgMsg.Items[i].FindControl("chkSelect") as CheckBox;
                    if (chk.Checked)
                    {
                        int sId = Convert.ToInt32(dgMsg.DataKeys[i]);
                        try
                        {
                            MsgBll.DeleteMsg(sId);
                        }
                        catch (Exception)
                        {
                            MessageBox.Alert("删除失败!", Page);
                            break;
                        }
                    }
                }
            }
            BindData();
        }