ASP.NET+ashx+jQuery动态添加删除表格
aspx:
<script src="../script/jquery-1.4.4.min.js" type="text/javascript" language="javascript"></script>
<script language="javascript" type="text/javascript">
var proID = <%=id %>;
var flag = 'True'; $(function(){
readStage();
}); function readStage(){
$.get(
'readstage.ashx?ajax=true&random=' + Math.random(),{'proID':proID},
function(result){
// var result = [
// {"StageName":"Brett","ProName":"McLaughlin","ID":"1"},
// {"StageName":"Jason","ProName":"Hunter","ID":"2"},
// {"StageName":"Elliotte","ProName":"Harold","ID":"3"}
// ];
addnewRow(eval(result));
}
);
} function addnewRow(values){
clearRow();
if(values.length == ){
var newTr = stageTable.insertRow();
var newTd1 = newTr.insertCell();
newTd1.setAttribute("colSpan",);
newTd1.innerHTML = '暂无数据记录...';
} if(flag == 'True'){
for(var i = ; i < values.length; i++){
//新行
var newTr = stageTable.insertRow(i+);
//序号
var newTd1 = newTr.insertCell();
newTd1.innerHTML = i + ;
//阶段名称
var newTd2 = newTr.insertCell();
newTd2.innerHTML = '<label id=' + values[i].StageName + ' type="text" alt="' + values[i].StageName + '" >' + values[i].StageName + '</label>';
//所属项目
var newTd3 = newTr.insertCell();
newTd3.innerHTML = values[i].ProName;
//修改
var newTd4 = newTr.insertCell();
newTd4.innerHTML = "<a href='#' id='edit'" + values[i].ID + "' onclick=\"editStage('" + values[i].ID + "','" + values[i].StageName + "')\">修改</a>";
//删除
var newTd5 = newTr.insertCell();
newTd5.innerHTML = "<a href='#' id='del'" + values[i].ID + "' onclick=\"delStage('" + values[i].ID + "','" + values[i].StageName + "','Del')\">删除</a>";
}
}else{
for(var i = ; i < values.length; i++){
//新行
var newTr = stageTable.insertRow(i+);
//序号
var newTd1 = newTr.insertCell();
newTd1.innerHTML = i + ;
//阶段名称
var newTd2 = newTr.insertCell();
newTd2.innerHTML = '<label id=' + values[i].StageName + ' type="text" alt="' + values[i].StageName + '" >' + values[i].StageName + '</label>';
//所属项目
var newTd3 = newTr.insertCell();
newTd3.innerHTML = values[i].ProName;
//修改
var newTd4 = newTr.insertCell();
newTd4.innerHTML = "<a href='#' id='edit'" + values[i].ID + "' disabled = 'true' onclick=\"editStage('" + values[i].ID + "','" + values[i].StageName + "')\">修改</a>";
//删除
var newTd5 = newTr.insertCell();
newTd5.innerHTML = "<a href='#' id='del'" + values[i].ID + "' disabled = 'true' onclick=\"delStage('" + values[i].ID + "','" + values[i].StageName + "','Del')\">删除</a>";
} //隐藏阶段操作条
document.getElementById('searchtitle').className = 'hidediv';
}
$('#stageTable').show();
//清空hidden
document.getElementById('hidStageID').value = ;
} //添加阶段
function addStage(operate){
var stageName = document.getElementById('txtStageName').value;
var id = document.getElementById('hidStageID').value;
if(stageName.length <= ){
alert('阶段名称不能为空!');
return;
}
$.get(
'savestage.ashx?ajax=true&random=' + Math.random(),{'proID':proID,'stageName':stageName,'ID':id,'operate':operate},
function(result){
if(result == 'S'){
alert('保存成功!');
readStage();
}
else if(result == 'E'){
alert('保存失败!');
}
else if(result == 'M')
{
alert('修改成功!');
readStage();
}
else
{
alert('修改失败!');
}
}
);
} //清除多余的行
function clearRow(){
var signFrame = document.getElementById("stageTable");
var rowscount = signFrame.rows.length;
//循环删除行,从最后一行往前删除
for(i=rowscount - ;i >; i--){
signFrame.deleteRow(i);
}
} //修改
function editStage(id,stagename){
document.getElementById('hidStageID').value = id;
document.getElementById('txtStageName').value = stagename;
} //删除
function delStage(id,stageName,operate){
if(confirm('确定要删除此信息?')){
$.get(
'delstage.ashx?ajax=true&random=' + Math.random(),{'proID':proID,'stageName':stageName,'ID':id,'operate':operate},
function(result){
if(result == 'S'){
alert('删除成功!');
readStage();
}else{
alert('删除失败!');
}
});
}
} function delMsg()
{
if(confirm('确定删除此项?'))
{
$.get("delproject.ashx?ajax=true&random="+Math.random(),{"proID":proID},
function(result){
if(result == 'S')
{
alert('删除成功!');
window.location="projectlist.aspx";
}
else
{
alert('删除失败!');
}
});
}
} </script> <div id="searchtitle">
<table width="66%" style="margin-top:10px" border="" cellpadding="" cellspacing="">
<tr>
<td width="23%">阶段名称:<asp:TextBox ID="txtStageName" runat="server" class="input"></asp:TextBox></td>
<td style="padding-left:10px" align="left"><input id="btnPost" type="button" value="保存" class="button" onclick="addStage('Add&Edit')"/></td>
</tr>
</table>
</div>
<asp:HiddenField ID="hidStageID" runat="server" />
<table border="" id="stageTable" class="infolist" style="width:65%; margin-left:0" cellpadding="" cellspacing="">
<thead>
<tr>
<th width="10%">序号</th>
<th width="25%">阶段名称</th>
<th>所属项目</th>
<th style="border-right:1px solid #999999;" colspan="" width="20%">操作</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
readstage.ashx:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
int projectID = Convert.ToInt32(context.Request["proID"]);
//PM.BLL.tb_Stage stagebll = new PM.BLL.tb_Stage();
//DataSet ds = stagebll.GetList(" ProjectID="+projectID);
//context.Response.Write(ds);
StringBuilder sb = new StringBuilder();
string sql = "select * from tb_Stage where ProjectID="+projectID;
DataSet ds = PM.DBUtility.DbHelperSQL.Query(sql);
sb.Append("[");
for (int i = ; i < ds.Tables[].Rows.Count; i++)
{
sb.Append("{");
string stagename = ds.Tables[].Rows[i]["StageName"].ToString();
sb.Append("\"StageName\":\"" + stagename + "\"");
sb.Append(",");
string proname = returnProName(ds.Tables[].Rows[i]["ProjectID"].ToString());
sb.Append("\"ProName\":\"" + proname + "\"");
sb.Append(",");
string id = ds.Tables[].Rows[i]["StageID"].ToString();
sb.Append("\"ID\":\"" + id + "\"");
sb.Append("}");
if (i != ds.Tables[].Rows.Count - )
{
sb.Append(",");
}
}
sb.Append("]");
context.Response.Write(sb);
} public string returnProName(string proid)
{
string str = new PM.BLL.tb_Project().GetModel(int.Parse(proid)).ProjectName;
return str;
}
savestage.ashx:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string stageName = context.Request["stageName"];
int projectId = Convert.ToInt32(context.Request["proID"]);
string operate = context.Request["operate"];
int id = Convert.ToInt32(context.Request["ID"]);
PM.Model.tb_Stage stagemod = new PM.Model.tb_Stage();
stagemod.StageName = stageName;
stagemod.ProjectID = projectId;
stagemod.StageID = id; PM.BLL.tb_Stage stagebll = new PM.BLL.tb_Stage();
if (id == )
{
int i = stagebll.Add(stagemod);
if (i > )
{
context.Response.Write("S");//保存成功
}
else
{
context.Response.Write("E");//保存失败
}
}
else
{
bool j = stagebll.Update(stagemod);
if (j == true)
{
context.Response.Write("M");//修改成功
}
else
{
context.Response.Write("ME");//修改失败
}
}
}
delstage.ashx:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
int stageId = Convert.ToInt32(context.Request["ID"]);
PM.BLL.tb_Stage stagebll = new PM.BLL.tb_Stage();
bool res = stagebll.Delete(stageId);
if (res == true)
{
context.Response.Write("S");
}
else
{
context.Response.Write("E");
}
}

ASP.NET+ashx+jQuery动态添加删除表格的更多相关文章
- Jquery动态添加/删除表格行和列
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- jQuery动态添加删除CSS样式
jQuery框架提供了两个CSS样式操作方法,一个是追加样式addClass,一个是移除样式removeClass,下面通过一个小例子讲解用法. jQuery动态追加移除CSS样式 <!DOCT ...
- jQuery动态添加删除select项
// 添加 function col_add() { var selObj = $("#mySelect"); var value="value"; var t ...
- jquery动态添加删除div--事件绑定,对象克隆
我想做一个可以动态添加删除div的功能.中间遇到一个问题,最后在manong123.com开发文摘 版主的热心帮助下解答了(答案在最后) 使用到的jquery方法和思想就是:事件的绑定和销毁(unbi ...
- jQuery动态添加删除与添加表行代码
具体实现代码如下: table的HTML如下: 代码如下 复制代码 <input type="button" value="添加一行" />< ...
- jquery动态添加/删除 tr/td
<head runat="server"> <title></title> <!--easyui --> <link rel= ...
- Jquery动态添加 删除 操作实现
这是gridView为空数据时显示的表头 下面直接填代码: function Add() { //动态添加行 $("#gridCustomerView").append(" ...
- 编辑 Ext 表格(一)——— 动态添加删除行列
一.动态增删行 在 ext 表格中,动态添加行主要和表格绑定的 store 有关, 通过对 store 数据集进行添加或删除,就能实现表格行的动态添加删除. (1) 动态添加表格的行 gridS ...
- jquery 动态添加表格行
jquery 动态添加表格行 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <h ...
随机推荐
- 李洪强iOS开发Swift篇—06_流程控制
李洪强iOS开发Swift篇—06_流程控制 一.swift中的流程控制 Swift支持的流程结构如下: 循环结构:for.for-in.while.do-while 选择结构:if.switch 注 ...
- SPRING IN ACTION 第4版笔记-第二章Wiring Beans-005-<constructor-arg>和c-namespace
1. package soundsystem; public class SgtPeppers implements CompactDisc { private String title = &quo ...
- perl use base 继承
centos6.5:/root/podinns/lib#cat First.pm package First; use base qw(Second); sub new { my $self = {} ...
- 17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制使用新的master和slaves:
17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制使用新的master和slaves: 最简单和最直接方式是设置复制使用新的 ...
- WCF Concurrency (Single, Multiple, and Reentrant) and Throttling
http://www.codeproject.com/Articles/89858/WCF-Concurrency-Single-Multiple-and-Reentrant-and Introduc ...
- RMA Sales Order – Stuck with “Awaiting Return Disposition”
RMA Sales Order – Stuck with "Awaiting Return Disposition" Action : (P ...
- statspack系列5
原文:http://jonathanlewis.wordpress.com/2006/12/27/analysing-statspack-5/ 作者:Jonathan Lewis 前些天,有人给我发了 ...
- SharePoint 2010中使用Visual Studio 2010进行方便快速的Web Part开发
转:http://www.cnblogs.com/fatwhale/archive/2010/02/24/1672633.html 在Visual Studio 2010中, 已经集成了用于Shar ...
- CSS实现Div透明,而显示在上面的文字不透明,但也可看到显示在下面的图片内容
CSS实现Div透明,而显示在上面的文字不透明,但也可看到显示在下面的图片内容,DiV透明其实挺简单,主要是为background定义opacity属性,一般这个是最大值是1,数值越接近1,则越不透明 ...
- A. Difference Row
A. Difference Row time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...