日期:2014-05-19  浏览次数:20503 次

datagrid 动态添加行
.net的页面里面有这样的需求:首先页面显示一行,然后左边(位置随意)有个 "增加 "按钮,点击在第一行下面增加一行,继续输入.再点击...也就是说每点击 "增加 "按钮一次,在结尾处就新建一行.最大10行.然后在页面的下面有个 "提交 "按钮.点击把所有的数据提交到数据库.请问谁可以给具体的代码?页面代码和CS代码.小弟才接触.net,公司要我做个这样的东西,我记得datagrid好象可以,但是我不知道具体的用法.各位大虾谁可以教教小弟?最好是有具体的代码.万分感谢了

------解决方案--------------------
//DynamicForm.aspx
<%@ Page language= "c# " Codebehind= "DynamicForm.aspx.cs " AutoEventWireup= "false " Inherits= "DynamicForm " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML>
<HEAD>
<title> WebForm1 </title>
<meta content= "Microsoft Visual Studio .NET 7.1 " name= "GENERATOR ">
<meta content= "C# " name= "CODE_LANGUAGE ">
<meta content= "JavaScript " name= "vs_defaultClientScript ">
<meta content= "http://schemas.microsoft.com/intellisense/ie5 " name= "vs_targetSchema ">
</HEAD>
<body>
<form runat= "server ">
<b> Product 1 </b>
<asp:textbox id= "txtProduct1 " Runat= "server "> </asp:textbox> <br>
<asp:placeholder id= "plh " runat= "server "> </asp:placeholder> <br>
<asp:button id= "btnAdd " Runat= "server " Text= "Add Product "> </asp:button> <asp:button id= "btnSubmit " Runat= "server " Text= "Submit "> </asp:button> </form>
</body>
</HTML>

------解决方案--------------------
ajax动态添加行。
------解决方案--------------------
ID重复错误,把这行去掉就应该没有错
TextBox txt = new TextBox();
//txt.ID = "txtProduct " + num;