Asp.net动态生成表单

2020-12-13 03:39

阅读:581

YPE html>

标签:blog   class   code   c   tar   ext   

control.ascx

?
1
2
3
4
"C#" AutoEventWireup="true" CodeBehind="control.ascx.cs" Inherits="WebApplication1.control" %>
  "Panel1" runat="server">
 
  "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
            {
                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;
            Liststring> lst = new Liststring>();
            foreach (var item in names)
            {
                if (item.Contains("control"))
                {
                    lst.Add(item);
                }
            }
            //遍历发送的key值
            for (int i = 0; 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
"C#" AutoEventWireup="true" CodeBehind="AutoPage.aspx.cs" Inherits="WebApplication1.AutoPage" %>
 
"~/control.ascx" TagPrefix="uc1" TagName="control" %>
 
 
 
"http://www.w3.org/1999/xhtml">
"server">
"Content-Type" content="text/html; charset=utf-8"/>
    
    
"form1" runat="server">
        "server" id="control" />
    

  

 

Asp.net动态生成表单,搜素材,soscw.com

Asp.net动态生成表单

标签:blog   class   code   c   tar   ext   

原文地址:http://www.cnblogs.com/anbylau2130/p/3726006.html


评论


亲,登录后才可以留言!