zoukankan      html  css  js  c++  java
  • Asp.net动态生成表单

    control.ascx

    <%@ 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" />
    

      

    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增加数据到数据库
                }
               
            }
        }
    }
    

      页面调用

    <%@ 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>
    

      

  • 相关阅读:
    Java Web 笔记(3)
    Java Web笔记(2)
    AndroidSystemDebug官方指导
    Android系统研究资料收集---站在前人的肩膀上
    算法--求出子序列中最大的和
    【CTS】几个serialno失败项
    GMS测试常用命令CTS&GTS&VTS
    cts-verifier测试流程
    通过例子手撕架构模式
    从0系统学Android--3.2四种基本布局
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/3726006.html
Copyright © 2011-2022 走看看