table循环显示数据
程序开发
2023-09-06 15:55:45
一直都在找一个关于table循环显示数据的应用,可找来找去,最终还是自己把它给做出来了,为了记得更深刻,现将它记录下来:
前台代码:
代码 <% @ Page Language = " C# " AutoEventWireup = " true " CodeBehind = " WebTable.aspx.cs " Inherits = " WebAppTable.WebTable " %>< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >
< title > title >
< style type = " text/css " >
td
{
border: 1px solid #C0C0C0;
}
style >
head >
< body >
< form id = " form1 " runat = " server " >
< div >
数据显示(Table): < br />
< table style = " font-size: 12px; background-color: #00FFFF; text-align: center; " >
< tr >< td > 姓名 td >< td > 年龄 td > tr >
<%
int Count = GetList().Count;
for ( int i = 0 ; i < Count; i ++ )
{
%>
< tr >< td ><%= GetList()[i].Name %> td >< td ><% Response.Write(GetList()[i].Age); %> td > tr >
<% }
%>
table >
div >
form >
body >
html >
后台的代码如下:
代码 using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// using ConsoleApplication_Generic;
namespace WebAppTable
{
public partial class WebTable : System.Web.UI.Page
{
int Count;
protected void Page_Load( object sender, EventArgs e)
{
if ( ! IsPostBack)
{
// Count = GetList().Count;
// Response.Write("
姓名 | 年龄 |
" + GetList()[i].Name + " | " + GetList()[i].Age + " |
}
}
///
/// 返回泛型集合列表
///
///
///
public List < Emp > GetList()
{
List < Emp > emplist = new List < Emp > ();
emplist.Add( new Emp( " 十九 " , 19 ));
emplist.Add( new Emp( " 二十 " , 20 ));
emplist.Add( new Emp( " 二十一 " , 21 ));
emplist.Add( new Emp( " 二十二 " , 22 ));
emplist.Add( new Emp( " 二十三 " , 23 ));
return emplist;
}
}
public class Emp
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
public Emp()
{ }
public Emp( string Name, int Age)
{
name = Name;
age = Age;
}
}
}
转载于:https://www.cnblogs.com/shengzh/archive/2010/12/20/1911561.html
标签:
上一篇:
weblogic的安装与配置(二)
下一篇:
相关文章
-
无相关信息