动态添加一行文本框,指定删除一行,取值

Default2.aspx文件

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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"> <div> <table id="test" border="1" width="210px"> <tr> <td> <input type="text" name="txtUser" /> <a href="#" onclick="addline()">添加</a> </td> </tr> </table> <asp:Button ID="Button1" runat="server" Text="提 交" OnClick="Button1_Click" /> <script type="text/javascript"><!-- function addline(content){ var strInerHtml='<input type="text" name="txtUser" /><a href="#" onclick="del()">删除此行</a>'; newline=document.all.test.insertRow(); newline.insertCell().innerHTML=strInerHtml; } function del(){ document.all.test.deleteRow(window.event.srcElement.parentElement.parentElement.rowIndex); } // --></script> </form> </body> </html>

 

 

 

Default2.aspx

using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string[] autotext = Request.Form["txtUser"].Split(',');//多个相同NAME的控件提交的值是以逗号分隔的, foreach (string item in autotext) { Response.Write(item+"</br>"); } } }

你可能感兴趣的:(动态添加一行文本框,指定删除一行,取值)