首页  ·  知识 ·  云计算
ASP.NET中如何做批量录入
佚名  本站原创  综合  编辑:dezai  图片来源:网络
"COLOR: #000000"> "COLOR: #000000; BACKGROUND-COLOR: #ffff00">% "COLOR: #000000; BACKGRO


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="test1.WebForm2" %>
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>Untitled Pagetitle>
   
<script src="Ajax.js" type="text/javascript">script>
   
<script type="text/javascript">
   
function func()
    {
       
var table = document.getElementById("test");
       
var tr = table.insertRow();//添加tr
        //tr.className = "xxx";
        var td1 = tr.insertCell();//添加td
        BuildText(td1,"newtext1");
       
var td2 = tr.insertCell();//添加td
        BuildText(td2,"newtext2");       

       
var url="WebForm2.aspx?type=getdata";       
       
var ajax = new AjaxCore.Ajax("POST",url,receiveInfo,null);
        ajax.SendRequest();    }
   
   
function receiveInfo(data)
    {
       
if(data.responseText == "false")
        {}
       
else if(data.responseText=="load")
        {}
       
else
        {
           
var str = data.responseText;
           
var json = eval('('+str+')');
           
            document.getElementById(
'newtext1').value = json.td1;
            document.getElementById(
'newtext2').value = json.td2;
        }
    }   
   
function BuildText(panel,id)
    {
       
var input = document.createElement("input");
        input.type
= "text";
        input.id
= id;
        input.name
= id;
        input.style.width
="95%";
        panel.appendChild(input);
    }
   
script>
head>
<body>
   
<form id="form1" runat="server">
   
<div>
   
<input type="button" onclick="func()" value="Add" />
   
<table id="test" width="50%" border="1">
       
<tr>
           
<td>ttttAtd>
           
<td>ttttBtd>
       
tr>
   
table>
   
  
div>
   
form>
body>
html>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace test1
{
   
public partial class WebForm2 : System.Web.UI.Page
    {
       
protected void Page_Load(object sender, EventArgs e)
        {
           
if (Request["type"] != null)
            {
               
if (Request["type"].ToString() == "getdata")
                {
                   
string json = "{{\"td1\":\"{0}\",\"td2\":\"{1}\"}}";
                    Response.Write(
string.Format(json,"aaaaa","bbbbb"));
                    Response.End();
                }
              
            }
        }
    }
}

ajax.js文件

var AjaxCore=new Object();
AjaxCore.Ajax
=function(type,url,onload,params,contentType){
   
this.req=null;
   
this.url=url;
   
this.params=params;
   
if(type){
       
this.type=type;
    }
else{
       
this.type="GET";
    }
   
if(!contentType && type=="POST"){
       
this.contentType="application/x-www-form-urlencoded; charset=UTF-8";
    }
else{
       
this.contentType=contentType;
    }
   
this.onload=onload;
   
this.responseText=null;
   
this.GetHttpRequest();
}

AjaxCore.Ajax.prototype.GetHttpRequest
=function(){
   
if(window.ActiveXObject){
       
this.req=new ActiveXObject("Microsoft.XMLHTTP");
    }
else if(window.XMLHttpRequest){
       
this.req=new XMLHttpRequest();
    }
}

AjaxCore.Ajax.prototype.SendRequest
=function(){
   
var loader=this;
   
this.req.onreadystatechange=function(){
        loader.OnReadyState.call(loader);
    }
   
this.req.open(this.type,this.url,true);
   
if(this.contentType){
       
this.req.setRequestHeader("Content-Type",this.contentType);
    }
   
this.req.send(this.params);
}

AjaxCore.Ajax.prototype.OnReadyState
=function(){
   
var ready=this.req.readyState;
   
var data;
   
if(ready==4){
       
if(this.req.status==200 || this.req.status==0){
           
this.responseText=this.req.responseText;
        }
else{
           
this.responseText="false";
        }
    }
else{
       
this.responseText="load";
    }
   
this.onload.call(this,this);
}

本文作者:佚名 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读