一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - ASP.NET教程 - 巧妙使用JQuery Clone 添加多行數(shù)據(jù),并更新到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼

巧妙使用JQuery Clone 添加多行數(shù)據(jù),并更新到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼

2019-09-24 10:37asp.net代碼網(wǎng) ASP.NET教程

巧妙使用JQuery Clone 添加多行數(shù)據(jù),并更新到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下。

web前端代碼: 

復(fù)制代碼代碼如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BatchAdd.aspx.cs" Inherits="BatchAdd" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title></title> 
</head> 
<body> 
<form id="form1" runat="server" action="BatchAdd.aspx"> 
<div> 
<table id="tblData"> 
<tr> 
<td> 
ID 
</td> 
<td> 
Title 
</td> 
<td> 
SmallClassName 
</td> 
<td> 
Author 
</td> 
<td> 
UpdateTime 
</td> 
</tr> 
<tr id="tRow0"> 
<td> 
<input type="text" id="txtID" name="txtID0" /> 
</td> 
<td> 
<input type="text" id="txtTitle" name="txtTitle0" /> 
</td> 
<td> 
<input type="text" id="txtSmallClassName" name="txtSmallClassName0" /> 
</td> 
<td> 
<input type="text" id="txtAuthor" name="txtAuthor0" /> 
</td> 
<td> 
<input type="text" id="txtUpdateTime" name="txtUpdateTime0" /> 
</td> 
</tr> 
</table> 
<input type="hidden" id="hidNum" name="hidNum" value="0" /> 
<input type="button" id="btnAdd" value="Add" /> 
<input type="submit" id="btnSave" value="Save" /> 
</div> 
</form> 
</body> 
</html> 
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script> 
<script language="javascript" type="text/javascript"> 
$(function() { 
$("#btnAdd").click(function() { 
var num = $("#hidNum").val(); // 
num = parseInt(num); 
num++; //點(diǎn)擊自加 
$("#hidNum").val(num); //重新賦值 
$("#tRow0").clone(true).attr("id", "tRow" + num).appendTo("#tblData"); //clone tr 并重新給定ID,裝到table 
$("#tRow" + num + " td").each(function() {//循環(huán)克隆的新行里面的td 
$(this).find("input[type='text']").val(""); //清空克隆行的數(shù)據(jù) 
//修改相關(guān)屬性 
$(this).find("input[name='txtID0']").attr("id", "txtID" + num).attr("name", "txtID" + num); 
$(this).find("input[name='txtTitle0']").attr("id", "txtTitle" + num).attr("name", "txtTitle" + num); 
$(this).find("input[name='txtSmallClassName0']").attr("id", "txtSmallClassName" + num).attr("name", "txtSmallClassName" + num); 
$(this).find("input[name='txtAuthor0']").attr("id", "txtAuthor" + num).attr("name", "txtAuthor" + num); 
$(this).find("input[name='txtUpdateTime0']").attr("id", "txtUpdateTime" + num).attr("name", "txtUpdateTime" + num); 
}); 
}); 
}); 
</script> 


cs頁(yè)面代碼: 

復(fù)制代碼代碼如下:


using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
public partial class BatchAdd : System.Web.UI.Page 

protected void Page_Load(object sender, EventArgs e) 

if (!string.IsNullOrEmpty(Request["hidNum"])) 

int num = Convert.ToInt32(Request["hidNum"]); 
string id, title, smallClassName, author, updatetime; 
int rs = 0; 
if (num > 0) 

for (int i = 0; i <= num; i++) 

id = Request["txtID" + i]; 
title = Request["txtTitle" + i]; 
smallClassName = Request["txtSmallClassName" + i]; 
author = Request["txtAuthor" + i]; 
updatetime = Request["txtUpdateTime" + i]; 
string sql = "insert into News(Title,SmallClassName,Author,Updatetime) values('" + title + "','" + smallClassName + "','" + author + "','" + updatetime + "')"; 
DBHelper.connString = "server=.;database=test;uid=sa;pwd=123"; 
if (DBHelper.ExecuteSql(sql) > 0) 
rs++; 

Response.Redirect("Manager.aspx?rs=" + rs); 



延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 97国产蝌蚪视频在线观看 | 天堂精品高清1区2区3区 | 男人插曲女人身体 | 国产成人精品免费视频软件 | 色噜噜亚洲男人的天堂www | 四虎影视在线影院在线观看观看 | 欧美日韩国产在线一区 | 久久精品国产欧美日韩99热 | 久久足恋网 | 人与善xuanwen在线400 | 99久久香蕉国产综合影院 | 爱情岛论坛亚洲永久入口口 | 呜呜别塞了啊抽插 | 欧美一区二区三区免费看 | 好舒服好爽再快点视频 | 国产一区二区三区日韩 | 日韩porn | 海派甜心完整版在线观看 | 波多野结衣52部合集在线观看 | 国产视频一区二区 | 婷婷伊人综合亚洲综合网 | 亚洲国产香蕉视频欧美 | 午夜宅男网 | 暖暖免费观看高清在线 | www.色婷婷.com| 国产第一综合另类色区奇米 | 欧美一区二区三区四区视频 | 热99精品在线| 国产精品亚洲午夜一区二区三区 | 亚洲国产欧美日韩在线一区 | 欧美8x8x | 欧美成人精品福利网站 | 久久精品国产色蜜蜜麻豆国语版 | 我的家教老师在线观看 | 免费观看网站 | 春宵福利网站在线观看 | 日本视频二区 | 精品一区二区三区波多野结衣 | 国产精品嫩草影院在线看 | 2015小明台湾永久区域免费 | 无码精品一区二区三区免费视频 |