To enable the content in the HTML interface to dynamically display the content required by the user based on the content in the database, or to dynamically create the page content based on different permissions.
Use htmlgenericcontrol to Create HTML tags
Introduce the namespace: using system. Web. UI. htmlcontrols;
Modify its attributes: hgg_div.attributes.add ("style", "width: 200px; Height: 200px ;");
Content Setting: hgg_div.innertext = "I am a" + htmltag; (htmltag can be div, BR, span ...)
Or innerhtml to write some HTML for the DIV
Use table newtable = new table (); To create a table control
Newtable. width = 200; set height
Newtable. Height = 200; set the width
Create row: tablerow newtablerow = new tablerow ();
Newtablerow. Height = 20;
Create a cell: tablecell newtablecell = new tablecell ();
Newtablecell. width = 100;
Newtablecell. Text = "I Am a cell ";
Add to table: newtablerow. Controls. Add (newtablecell );
Newtablerow. Controls. Add (newtablecell );
Newtable. Controls. Add (newtablerow );
Add the created tag or control to the page.
Page. Controls. Add (newtable); // Add it outside the form (Control)
Page. Form. innerhtml = STR; // Add to form (HTML)
1 Using System; 2 Using System. Collections. Generic; 3 Using System. LINQ; 4 Using System. Web; 5 Using System. Web. UI; 6 Using System. Web. UI. webcontrols; 7 8 # Region Introduce namespace9 10 Using System. Web. UI. htmlcontrols; 11 12 # Endregion 13 14 15 Namespace Web_createhtml 16 { 17 Public Partial Class _ Default: system. Web. UI. Page 18 { 19 # Region Form Loading 20 21 Protected Void Page_load ( Object Sender, eventargs E) 22 { 23 Createhtmltag (" Div " ); // Create a div 24 Createtable (); // Create a table control 25 Jointhtmltag (); // Concatenate a div 26 } 27 28 # Endregion 29 30 # Region Create htmltag 31 32 /// <Summary> 33 /// Common methods for creating tags such as Div, BR, and Span 34 /// </Summary> 35 Private Void Createhtmltag (String Htmltag) 36 { 37 Htmlgenericcontrol hgg_div = New Htmlgenericcontrol (htmltag ); 38 Hgg_div.attributes.add ( " Style " , " Width: 200px; Height: 200px; " ); 39 Hgg_div.innertext = " I am " + Htmltag; 40 Page. Controls. Add (hgg_div ); 41 } 42 43 # Endregion 44 45 # Region Create a table control46 47 /// <Summary> 48 /// Create a table control 49 /// </Summary> 50 Private Void Createtable () 51 { 52 Table newtable = New Table (); 53 Newtable. width = 200 ; 54 Newtable. Height = 200 ; 55 Tablerow newtablerow = New Tablerow (); 56 Newtablerow. Height = 20 ; 57 Tablecell newtablecell = New Tablecell (); 58 Newtablecell. width = 100 ; 59 Newtablecell. Text = " I am a cell " ; 60 61 Newtablerow. Controls. Add (newtablecell ); 62 Newtablerow. Controls. Add (newtablecell ); 63 Newtable. Controls. Add (newtablerow ); 64 Page. Controls. Add (newtable ); 65 } 66 67 # Endregion 68 69 # Region String concatenation html 70 71 /// <Summary> 72 /// String concatenation html 73 /// </Summary> 74 Private Void Jointhtmltag () 75 { 76 String STR =" <Div style = 'width: 200px; Height: 200px; '> I am a spliced Div. </div> " ; 77 Page. Form. innerhtml = STR; 78 } 79 80 # Endregion 81 } 82 }
The source code is appended: asp.netcreates a Real-Time HTML Tag layout (table,div,br...20..zip
author: Zeng qinglei Source: Beijing, the original Article link is displayed on the Article page, otherwise, the legal liability is retained.