Use the web control table in. Net to dynamically generate a table

Source: Internet
Author: User

. Aspx file:

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "t1.aspx. cs" inherits = "T1" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">

<Head runat = "server">

<Title> No title page </title>

</Head>

<Body>

<Form method = "Post" runat = "server">

<Asp: Label style = "Z-INDEX: 101; left: 41px; top: 33px" runat = "server"> Asp. net table control dynamically generates table operation instances </ASP: Label> & nbsp;

<Asp: Table Style = "Z-INDEX: 104; left: 35px; top: 89px "runat =" server "gridlines =" both "bordercolor =" # ffc080 "borderstyle =" dotted "borderwidth =" 1px "cellpadding =" 0 "cellspacing =" 0 "Height = ""153px" width = "344px">

</ASP: Table>

</Form>

</Body>

</Html>

. CS file:

Using system;

Using system. Data;

Using system. configuration;

Using system. collections;

Using system. Web;

Using system. Web. Security;

Using system. Web. UI;

Using system. Web. UI. webcontrols;

Using system. Web. UI. webcontrols. webparts;

Using system. Web. UI. htmlcontrols;

Public partial class T1: system. Web. UI. Page

{

Protected void page_load (Object sender, eventargs E)

{

Int I, J;

For (I = 0; I <6; I ++) // 6 rows

{

Tablerow ROW = new tablerow ();

For (j = 0; j <4; j ++) // 4 columns

{

Tablecell cell = new tablecell ();

Cell. Text = "column =" + J. tostring ();

If (j = 3) // Add button control in column 4th

{

Button btna = new button ();

Btna. Text = "column = 3 ";

Cell. Controls. Add (btna );

}

Row. cells. Add (cell );

}

Table1.rows. Add (ROW );

}

}

}

 

:

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.