Asp. NET to create and use Web Components dynamically based on XML (II)

Source: Internet
Author: User
Tags tostring
asp.net|web|xml| Create | dynamic ASP. NET to create the use of Web Components dynamically based on XML

Two

Author: Shing

Third, dynamically create Web Components.

First look at the program example:

private void createconfigtable (int totalnum,int[] sequenceint,string[] namestr,string[] ipstr)

{

Dynamically generate an input box based on the total number of points being measured

for (int i=1;i<=totalnum;i++)

{

Create a table

HtmlTable showtable = new HtmlTable ();

Showtable. border=0;

Showtable.id= "Showtable" +i.tostring ();

Showtable. Bordercolor= "#000000";

Showtable. cellpadding=4;

Showtable. cellspacing=4;

Showtable. align= "center";

MYPLACEHOLDER.CONTROLS.ADD (showtable);

Create a row

HtmlTableRow Trow = new HtmlTableRow ();

Showtable. Rows.Add (Trow);



Create first column (ordinal)

HtmlTableCell Tcell = new HtmlTableCell ();

Label Sequencelabel = new label ();

Sequencelabel.id= "Sequencelabel" +i.tostring ();

Sequencelabel.text= "serial 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.tostring ();

Sequencedatatb.text=i.tostring ();

sequencedatatb.width=30;

Sequencedatatb.text=sequenceint[i]. ToString ();

Sequencedatatb.readonly=false;





Create third column (name)

Tcell = new HtmlTableCell ();

Label Namelabel = new label ();

Namelabel.id= "Namelabel" +i.tostring ();

namelabel.text= "Name:";

Namelabel.enabled=true;

TCELL.CONTROLS.ADD (Namelabel);

TROW.CELLS.ADD (Tcell);



Create fourth Column

Tcell = new HtmlTableCell ();

Nametb=new TextBox ();

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

nametb.width=120;

Nametb.text=namestr[i];

nametb.maxlength=50;

TCELL.CONTROLS.ADD (NAMETB);

TROW.CELLS.ADD (Tcell);



Create 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 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 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 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);

}

}



































































































































The Myplaceholder in the program is the System.Web.UI.WebControls.PlaceHolder component, and the HTML syntax for using the component is as follows:

... ...

<tr>

<td>

<asp:placeholder id= "Myplaceholder" runat= "Server" ></asp:PlaceHolder>

</td>

</tr>

... ...



















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

Another place to be described in the program is the setting of the ID of the dynamically created component. Set the ID of the component to note two points:

1, ID number can not be repeated

2, to facilitate the use of the program. Because you want to use dynamically created components in your program, you are looking through the component's ID. (In this connection, the "use of dynamically created Web Components" section is described in more detail)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.