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();
      } 

  • 相关阅读:
    DEDE更改版权信息
    apache 服务器端口被IIS服务器占用
    解析html与xhtml的神器——HTMLParser与SGMLParser
    正则匹配牛刀小试——一键抓取奇虎360新闻信息
    urllib2模块初体验———豆瓣读书页面下载小爬虫
    urllib模块和urllib2模块的区别
    cookielib和urllib2模块相结合模拟网站登录
    Python核心模块——urllib模块
    《java语言程序设计》初步学习——各种小Demo
    Python核心编程——Chapter15
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306873.html
Copyright © 2011-2022 走看看