写在*.aspx中
1 //删除行 OK 2 var myDeleteRow = function () { 3 var DBID = document.getElementById("my_textbox").value; 4 //var tempConfirm = confirm("DBID为:" + DBID); //弹出确认框 5 var tempConfirm = confirm("确定删除吗?"); //弹出确认框 6 if (tempConfirm == true) { 7 $.ajax({ 8 url: "Handler2.ashx", //删除行_写入数据库 9 datatype: "json", 10 data: { "RequestType": "deleted_Row", "DBID": DBID }, 11 success: function (data) { 12 document.getElementById('spreadsheet').jexcel.refresh(); //刷新表格 13 }, 14 error: function (error) { 15 alert(error.responseText); 16 } 17 }); 18 } 19 };View Code
辅助删除代码(将选中的行ID,存放到页面的文本框中,文本框要做隐藏。)
1 //点击单元格,获取行列坐标 OK 2 var selectionActive = function (instance, x1, y1, x2, y2, origin) { 3 var cellName = jexcel.getColumnNameFromId([0, y1]); 4 var DBID = document.getElementById('spreadsheet').jexcel.getValue(cellName); 5 document.getElementById("my_textbox").value = DBID; 6 7 //var data = document.getElementById('spreadsheet').jexcel.getData().length;//表格上显示的数据或公式 8 //var tempConfirm = confirm("DBID:" + DBID + " data:" + data); //弹出确认框 9 10 };View Code
写在*.ashx中
1 //前端删除行_写入数据库 OK 2 if (context.Request["RequestType"] == "deleted_Row") //save_data是homePage.aspx中自定义的请求类型 3 { 4 string dbId = context.Request["DBID"].ToString(); //ID 5 string s0 = "delete from outstanding where id=" + dbId; 6 7 //确认查询语句,是否正确 8 //context.Response.Write(s0); 9 10 //往数据库写入新信息 11 SqlConnection conn = new SqlConnection("server=*.*.*.*;database=*;uid=*;pwd=*"); 12 conn.Open(); 13 //SqlCommand cmd = new SqlCommand(s0, class1.GetConnection1()); //用来执行查询语句 14 SqlCommand cmd = new SqlCommand(s0, conn); 15 //SqlCommand mycmd = new SqlCommand(strsql, myconn); 16 cmd.ExecuteNonQuery(); //执行SQL语句,返回受影响的行数 17 cmd.Dispose(); //释放资源 18 conn.Close(); 19 20 };View Code
标签:删除,DBID,数据库,jexcel,var,document,data,SqlCommand From: https://www.cnblogs.com/automationanywhere/p/17479670.html