<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    302班

    java突擊隊(duì)
    posts - 151, comments - 74, trackbacks - 0, articles - 14
      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

     public class SelAndDropAll : System.Web.UI.Page
     {
      protected System.Web.UI.WebControls.Button btnDelete;
      protected System.Web.UI.WebControls.DataGrid dgShow;
     
      private void Page_Load(object sender, System.EventArgs e)
      {
       // 在此處放置用戶(hù)代碼以初始化頁(yè)面
       //添加確認(rèn)刪除事件
       btnDelete.Attributes.Add("onclick", "return confirm('您真的要?jiǎng)h除所選項(xiàng)嗎?');");
       if(!IsPostBack)
        BindData();
       
      }
      //初始化綁定
      private void BindData()
      {
       string strCon = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
       SqlConnection con = new SqlConnection(strCon);
       SqlDataAdapter da = new SqlDataAdapter("Select * from tbStudentinfo",con);
       DataSet ds = new DataSet();
       da.Fill(ds,"studentinfo");
       dgShow.DataSource = ds.Tables["studentinfo"].DefaultView;
       dgShow.DataBind();
      }
      #region Web Form Designer generated code
      override protected void OnInit(EventArgs e)
      {
       //
       // CODEGEN:該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
       //
       InitializeComponent();
       base.OnInit(e);
      }
      
      /// <summary>
      /// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
      /// 此方法的內(nèi)容。
      /// </summary>
      private void InitializeComponent()
      {   
       this.dgShow.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgShow_PageIndexChanged);
       this.dgShow.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgShow_CancelCommand);
       this.dgShow.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgShow_EditCommand);
       this.dgShow.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgShow_UpdateCommand);
       this.dgShow.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgShow_DeleteCommand);
       this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
       this.Load += new System.EventHandler(this.Page_Load);

      }
      #endregion
    // 編輯

    private void dgShow_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
      {
       dgShow.EditItemIndex = e.Item.ItemIndex;
       BindData();

      }
     //取消編輯
      private void dgShow_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
      {
       dgShow.EditItemIndex = -1;
       BindData();
      }
      //定義翻頁(yè)事件
      private void dgShow_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
      {
       dgShow.CurrentPageIndex = e.NewPageIndex;
       BindData();
      }
    //刪除事件
      private void dgShow_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
      {
       if(dgShow.Items.Count==1)
       {
        if(dgShow.CurrentPageIndex!=0)
         dgShow.CurrentPageIndex = dgShow.CurrentPageIndex-1;
       }
       string strSql = "delete from tbStudentinfo where studentid="+e.Item.Cells[0].Text+"";
       ExecuteSql(strSql);
       BindData();

      }
      ////////////////////////////////////////////////////////////
      //說(shuō)明:執(zhí)行制定SQL語(yǔ)句/////////////////////////////////////
      ///////////////////////////////////////////////////////////
      private void ExecuteSql(string strSql)
      {
       try
       {
        string strconn = System.Configuration.ConfigurationSettings.AppSettings["DSN"];//從Web.config中讀取
        SqlConnection conn =new SqlConnection(strconn);
        SqlCommand com = new SqlCommand(strSql,conn);
        conn.Open();
        com.ExecuteNonQuery();
        conn.Close();
       }
       catch(Exception e)
       {
        Response.Write("<script language = 'javascript'>alert('"+e.Message+"');</script>") ;
           
       }
      }
      //更新數(shù)據(jù)
      private void dgShow_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
      {
       string strStudentID = e.Item.Cells[0].Text;//處于非編輯狀態(tài)
       string strName = ((TextBox)(e.Item.Cells[1].Controls[0])).Text;//處于編輯狀態(tài)
       string strPass =((TextBox)(e.Item.Cells[2].Controls[0])).Text;
       string strSex = ((CheckBox)(e.Item.Cells[3].FindControl("cbSex"))).Checked?"1":"0";
       string strBirthday =((TextBox)(e.Item.Cells[4].Controls[0])).Text;
       string strEmail =((TextBox)(e.Item.Cells[5].Controls[0])).Text;
       string strSql = "update tbStudentinfo set StudentName='"+strName+"',StudentPass='"+strPass+"'";
       strSql +=",Sex="+strSex+",Birthday='"+strBirthday+"',Email='"+strEmail+"' where studentid="+strStudentID+"";
       ExecuteSql(strSql);
       dgShow.EditItemIndex = -1;
       BindData();

      }
    //全選事件
      public void CheckAll(object sender, System.EventArgs e)
      {
       CheckBox cbAll = (CheckBox)sender;
       if(cbAll.Text=="全選")
       {
        foreach(DataGridItem dgi in dgShow.Items)
        {
         CheckBox cb = (CheckBox)dgi.FindControl("cbSelect");
         cb.Checked = cbAll.Checked;
        }
       }
      }

    //刪除按鈕事件
      private void btnDelete_Click(object sender, System.EventArgs e)
      {
       foreach(DataGridItem dgi in dgShow.Items)
       {
        CheckBox cb = (CheckBox)dgi.FindControl("cbSelect");
        if(cb.Checked)
        {
         //以下執(zhí)行刪除操作
         int nID = int.Parse(dgi.Cells[0].Text);
         string strSql = "delete from tbStudentinfo where studentid="+nID;
         ExecuteSql(strSql);
        }
       }
       dgShow.CurrentPageIndex = 0;
       BindData();
      }

     }
    }

    主站蜘蛛池模板: 亚洲一区二区三区乱码A| 久久经典免费视频| 黄色短视频免费看| 国产区在线免费观看| 亚洲精品国产电影| 亚洲乱码在线视频| 国产成人亚洲综合无| jizz18免费视频| 国产成人精品免费午夜app| 国产在线19禁免费观看国产| 亚洲中文字幕丝袜制服一区| 午夜成人无码福利免费视频| 日日麻批免费40分钟无码| 成人啪精品视频免费网站| 国产亚洲av片在线观看18女人| 亚洲人成在线免费观看| 青青草免费在线视频| 亚洲gv猛男gv无码男同短文| 久久亚洲精品专区蓝色区| a高清免费毛片久久| 亚洲免费观看视频| 羞羞漫画小舞被黄漫免费| 免费观看美女用震蛋喷水的视频 | 国产精品无码一区二区三区免费| 亚洲国产精品日韩av不卡在线| 亚洲视频在线观看免费| 亚洲欧洲精品成人久久曰影片 | 免费黄网站在线观看| 午夜亚洲av永久无码精品| 在线观看亚洲人成网站| 久99久无码精品视频免费播放| 亚洲AV无码乱码国产麻豆穿越| 91香蕉国产线在线观看免费| 国产AV无码专区亚洲AV手机麻豆| 亚洲高清一区二区三区电影| 亚洲人成色7777在线观看不卡| 日韩精品久久久久久免费| 亚洲熟妇AV一区二区三区浪潮| 精品久久久久久国产免费了| 亚洲国语精品自产拍在线观看| 99精品视频在线观看免费|