zoukankan      html  css  js  c++  java
  • DataGrid经典编辑更新删除代码

    private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
      {   
       DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
       BindGrid();
      }

      private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
      {
       DataGrid1.CurrentPageIndex=e.NewPageIndex;
       BindGrid();
      }

      private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
      {
       SqlCommand cm=new SqlCommand("deleteEmp",mySqlConn);
       cm.CommandType=CommandType.StoredProcedure;
       cm.Parameters.Add(new SqlParameter("@Empid",SqlDbType.Int,4));
       cm.Parameters["@Empid"].Value=DataGrid1.DataKeys[(int)e.Item.ItemIndex];
      
       cm.Connection.Open();
       try
       {
        cm.ExecuteNonQuery();
        Label1.Text="删除成功";
       
       }
       catch(SqlException)
       {
        Label1.Text="删除失败";
        Label1.Style["color"]="red";
       }
       cm.Connection.Close();  
       BindGrid();
      }

      private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
      {
       DataGrid1.EditItemIndex=-1;   
       BindGrid();
      }

      private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
      {
       SqlCommand cm=new SqlCommand("UpdateEmp",mySqlConn);
       cm.CommandType=CommandType.StoredProcedure;
          
       cm.Parameters.Add(new SqlParameter("@Email",SqlDbType.VarChar,50));  
       cm.Parameters.Add(new SqlParameter("@tell",SqlDbType.VarChar,50));
       cm.Parameters.Add(new SqlParameter("@jb",SqlDbType.Int,4));
       cm.Parameters.Add(new SqlParameter("@Emp_id",SqlDbType.Int,4));
       string colvalue=((TextBox)e.Item.Cells[4].Controls[0]).Text;
       cm.Parameters["@Email"].Value=colvalue;
     
       colvalue=((TextBox)e.Item.Cells[5].Controls[0]).Text;
       cm.Parameters["@jb"].Value=colvalue;
       colvalue=((TextBox)e.Item.Cells[6].Controls[0]).Text;
       cm.Parameters["@tell"].Value=colvalue;
        
       cm.Parameters["@Emp_id"].Value=DataGrid1.DataKeys[(int)e.Item.ItemIndex];
       cm.Connection.Open();
       try
       {
        cm.ExecuteNonQuery();
        Label1.Text="编辑成功";
        DataGrid1.EditItemIndex=-1;
       }
       catch(SqlException)
       {
        Label1.Text="编辑失败";
        Label1.Style["color"]="red";
       }
       cm.Connection.Close(); 
       BindGrid();
      } 

  • 相关阅读:
    Spring AOP 随记
    Java设计模式系列 — 构造器模式
    【Java线程安全】 — 常用数据结构及原理(未完结)
    【最佳实践】好用的Quartz管理器类
    Timer和时间调度
    Java9之HashMap与ConcurrentHashMap
    记一次maven的包冲突经历
    hbase高可用集群部署(cdh)
    HBase 1.2.6 完全分布式集群安装部署详细过程
    hadoop-2.7.3完全分布式部署
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306873.html
Copyright © 2011-2022 走看看