How to dynamically generate page controls and get the value? (.NET)

zhaozj2021-02-16  78

The control of the page is generated in the CS and operates

1) page Add a button

2) Execute CreateTab in Page_Load to ensure that when you refresh the leaves, the dynamic form will not disappear. If you click on the incident, you will find the button once a button will be redrawn.

Private void page_load (Object sender, system.eventargs e) ?? {??? if (! page.ispostback) ??? {?????} ??? Else ??? {??????? CreateTab (TextBox1.text, TextBox2.text); ???} ?????? // Place the user code here to initialize the page?

3) Generate a dynamic table button Click the event does not need to write any code

Private void button1_click (object sender, system.eventargs e) ?? {??}

4) Generate a dynamic form ?? ///

?? // / Generate a dynamic table ?? ///

?? ///

Rows

?? ///

Column number

?? Private Void CreateTab (String Rows, String Cols)

?? {

??? if (rows! = "" && colors! = "")??

??? {

???? Table table1 = new table ();

????

???? for (int i = 0; i

???? {

????? TableRow TR = new tableRow ();

????? for (int J = 0; J

????? {

?????? Tablecell td = new TableCell ();

?????? td.width = 100;

????

?????? textbox txt = new textbox ();

?????? txt.id = "txt" i.toString () j.toString ();

?????? txt.width = 100;?

?????? txt.borderStyle = borderstyle.groove; ?????

?????? IF (i == 0 || j == 0)

?????? {

??????? txt.backcolor = system.drawing.color.lightyellow;

??????? txt.readonly = false;

????????

??????}

?????? ELSE

?????? {

??????? TXT.BACKCOLOR = system.drawing.color.silver;

??????? txt.readonly = true;

??????} ?????? IF (i == 0 && j == 0) ?????? {??????? txt.backcolor = system.drawing.color.silver ;? ?????? txt.readonly = true; ??????} ??????????????????????? Td.controls.Add (TXT) ; ??????????? tr.cells.add (TD); ???????????????} ????? Table1.Controls.Add (TR); ????} ???? Table1.id = "Temptab"; ???? Table1.cellpadding = 0; ???? Table1.cellspacing = 0; ???? Table1.BorderWidth = 1;??? TABLE1.BORDERWIDTH = UNIT.PIXEL (1); ??????????????? Table1.backcolor = system.drawing.color.fromname ("# D4D0C8"); ???? Table1 .BackColor = system.drawing.color.fromname ("# D4D0C8"); ???? Tab1.controls.add (table1); ???} ?????} 5) Take the value of dynamic controls

Request.form.get ("txt00")

Request.form.get ("txt11)

转载请注明原文地址:https://www.9cbs.com/read-12641.html

New Post(0)