protected void btnDelSelect_Click(object sender, EventArgs e) { int selectNum = 0; for (int i = 0; i < dgNews.Items.Count; i++) { CheckBox chk = dgNews.Items[i].FindControl("chkSelect") as CheckBox; if (chk.Checked) { selectNum++; } } if (selectNum == 0) { MessageBox.Alert("请选择要删除的项!", Page); } else { for (int i = 0; i < dgNews.Items.Count; i++) { CheckBox chk = dgNews.Items[i].FindControl("chkSelect") as CheckBox; if (chk.Checked) { int sId = Convert.ToInt32(dgNews.DataKeys[i]); try { NewsBll.DeleteNews(sId); } catch (Exception) { MessageBox.Alert("删除失败!", Page); break; } } } } BindData(); }
protected void dgNews_ItemCommand(object source, DataGridCommandEventArgs e) { switch (e.CommandName.ToLower()) { case "status": int newsId = Convert.ToInt32(e.CommandArgument); List <Model.News> list = NewsBll.GetNewsbyId(newsId); if (list.Count > 0) { if (list[0].IsShow == 0) { try { NewsBll.UpdateStatus(newsId, 1); BindData(); } catch (Exception ex) { MessageBox.Alert("未知错误:" + ex, Page); /*throw;*/ } } else { try { NewsBll.UpdateStatus(newsId, 0); BindData(); } catch (Exception ex) { MessageBox.Alert("未知错误:" + ex, Page); /*throw;*/ } } } break; case "top": int newsId1 = Convert.ToInt32(e.CommandArgument); List <Model.News> list1 = NewsBll.GetNewsbyId(newsId1); if (list1.Count > 0) { if (list1[0].IsTop == 0) { try { NewsBll.UpdateTop(newsId1, 1); BindData(); } catch (Exception ex) { MessageBox.Alert("未知错误:" + ex, Page); /*throw;*/ } } else { try { NewsBll.UpdateTop(newsId1, 0); BindData(); } catch (Exception ex) { MessageBox.Alert("未知错误:" + ex, Page); /*throw;*/ } } } break; case "index": int newsId2 = Convert.ToInt32(e.CommandArgument); List <Model.News> list2 = NewsBll.GetNewsbyId(newsId2); if (list2.Count > 0) { if (list2[0].IndexShow == 0) { try { NewsBll.UpdateIndex(newsId2, 1); BindData(); } catch (Exception ex) { MessageBox.Alert("未知错误:" + ex, Page); /*throw;*/ } } else { try { NewsBll.UpdateIndex(newsId2, 0); BindData(); } catch (Exception ex) { MessageBox.Alert("未知错误:" + ex, Page); /*throw;*/ } } } break; case "del": int id = Convert.ToInt32(e.CommandArgument); try { NewsBll.DeleteNews(id); MessageBox.Alert("删除成功!", Page); BindData(); } catch (Exception) { MessageBox.Alert("删除失败!", Page); /*throw;*/ } break; default: break; } }