ASP.NET is created and used in XML dynamics and uses web components (2)

zhaozj2021-02-16  53

ASP.NET is based on XML dynamic creation Web components (2)

Author: Li Tieshuai

Third, dynamically create a web component.

Let's see the program example:

Private Void CreateconfigTable (int totalnum, int [] sequenceint, string [] namestr, string [] IPSTR)

{

/ / Dynamically generate input box according to the total number of measurement points

For (int i = 1; i <= totalnum; i )

{

// Create a form

Htmltable showtable = new htmltable ();

ShowTable.Border = 0;

ShowTable.id = "ShowTable" i.toToString ();

ShowTable.BorderColor = "# 000000";

Showtable.cellpadding = 4;

ShowTable.cellspacing = 4;

ShowTable.Align = "center";

myplaceholder.controls.add (showtable);

// Create a line

HTMLTABLEROW TROW = New HTMLTABLEROW ();

ShowTable.Rows.Add (TROW);

// Create a first column (serial number)

HTMLTablecell Tcell = New HTMLTableCell ();

Label sequencelabel = new label ();

Sequencelabel.id = "sequencelabel" i.toT7tring ();

SequenceLabel.Text = "Sequence Number:";

SEQUENCELABEL.ENABLED = True;

Tcell.Controls.Add (SequenceLabel);

Trow.cells.Add (TCELL);

// Create a second column

Tcell = new htmltablecell ();

SequenceDataTb = new textbox ();

SequenceDataTb.id = "sequencedatatb" i.toT7tring ();

SequenceDataTb.Text = i.tostring ();

SEQUENCEDATATB.WIDTH = 30;

SequencedataTb.Text = Sequenceint [i] .tostring ();

SequenceDataTb.readonly = false;

// Create a third column (name)

Tcell = new htmltablecell ();

Label Namelabel = new label ();

Namelabel.id = "Namelabel" i.toTostring ();

Namelabel.text = "Name:";

Namelabel.enabled = TRUE;

Tcell.Controls.Add (Namelabel);

Trow.cells.Add (TCELL);

// Create a fourth column

Tcell = new htmltablecell ();

Nametb = new textbox ();

Nametb.id = "Nametb" i.tostring ();

Nametb.width = 120;

Nameetb.text = namestr [i];

Nametb.maxlength = 50; Tcell.controls.Add (Nametb);

Trow.cells.Add (TCELL);

// Create a fifth column (IP)

Tcell = new htmltablecell ();

Label iplabel = new label ();

iplabel.id = "iplabel" i.toString ();

IPLabel.Text = "IP:";

iplabel.enabled = true;

Tcell.Controls.Add (IPLabel);

Trow.cells.Add (TCELL);

// Create a sixth column

Tcell = new htmltablecell ();

IPTB = new textbox ();

iptb.id = "iptb" i.toString ();

iptb.width = 120;

IPTB.Text = IPSTR [i];

iptb.maxlength = 15;

Tcell.Controls.Add (IPTB);

Trow.cells.Add (TCELL);

}

}

Tcell.controls.add (sequencedatatb);

Trow.cells.Add (TCELL);

...

// Create a fifth column (IP)

Tcell = new htmltablecell ();

Label iplabel = new label ();

iplabel.id = "iplabel" i.toString ();

IPLabel.Text = "IP:";

iplabel.enabled = true;

Tcell.Controls.Add (IPLabel);

Trow.cells.Add (TCELL);

// Create a sixth column

Tcell = new htmltablecell ();

IPTB = new textbox ();

iptb.id = "iptb" i.toString ();

iptb.width = 120;

IPTB.Text = IPSTR [i];

iptb.maxlength = 15;

Tcell.Controls.Add (IPTB);

Trow.cells.Add (TCELL);

}

}

MyPLACEHOLDER in the program is System.Web.ui.WebControls.PlaceHolder component, using this component's HTML syntax as follows:

...

...

The purpose of using this component is to locate a dynamically created table. The location of the component is a dynamically created table in the location of the page.

Another place to be described in the program is the setting of the ID of the component that is dynamically created. The settings of the components should be paid to two points:

1, ID number can't be repeated

2, easy to use in the program. Because dynamically created components to be used in the program, you should find it through the ID of the component. (About this, there will be a more detailed introduction in "Web Components that use dynamic creation".

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

New Post(0)