Asp.net動態產生表單

來源:互聯網
上載者:User

標籤:blog   class   code   c   tar   ext   

control.ascx

?
1 2 3 4 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="control.ascx.cs" Inherits="WebApplication1.control" %>   <asp:Panel ID="Panel1" runat="server"></asp:Panel>     <input id="Submit1" type="submit" value="submit" />

  

 

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;   namespace WebApplication1 {     public partial class control : System.Web.UI.UserControl     {         protected void Page_Load(object sender, EventArgs e)         {             GetFormData();                 AddFormTable();                                     }           private void AddFormTable()         {             Table tb = new Table();               for (int i = 0; i < 10; i++)             {                 TableRow tr = new TableRow();                 TableCell tc1 = new TableCell();                   TextBox txtbox = new TextBox();                 txtbox.ID = "AutoPageControl_" + i.ToString();                 tc1.Controls.Add(txtbox);                 tr.Cells.Add(tc1);                 tb.Rows.Add(tr);             }             Panel1.Controls.Add(tb);         }             public void GetFormData()         {             string[] names = Request.Form.AllKeys;             List<string> lst = new List<string>();             foreach (var item in names)             {                 if (item.Contains("control"))                 {                     lst.Add(item);                 }             }             //遍曆發送的key值             for (int i = 0; i < lst.Count; i++)             {                 string[] arr = lst[i].Split(‘_‘);                   string attribute = arr[arr.Length - 1];                 //@TODO擷取資料庫中資料模型,判斷是否必填項和是否是確認項                 string value = Request[lst[i]];                 //@TODO增加資料到資料庫             }                      }     } }

  頁面調用

 

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AutoPage.aspx.cs" Inherits="WebApplication1.AutoPage" %>   <%@ Register Src="~/control.ascx" TagPrefix="uc1" TagName="control" %>     <!DOCTYPE html>   <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>     <title></title> </head> <body>     <form id="form1" runat="server">         <uc1:control runat="server" id="control" />     </form> </body> </html>

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.