index.aspx代码如下:
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5
<html xmlns="http://www.w3.org/1999/xhtml" >
6
<head runat="server">
7
<title>Table控件布局DataList模板</title>
8
</head>
9
<body>
10
<form id="form1" runat="server">
11
<div align="center">
12
<asp:DataList ID="DataList1" runat="server" Width="365px" BackColor="#FFC080">
13
<ItemTemplate>
14
<table style="width: 390px; height: 71px; font-size: 9pt; background-color: #ffffcc;" align="center" border="1">
15
<tr>
16
<td style="width: 61px; height: 17px">
17
姓 名:</td>
18
<td style="width: 78px; height: 17px">
19
<asp:Label ID="Label1" runat="server"><%# DataBinder.Eval(Container.DataItem,"name") %></asp:Label></td>
20
<td style="width: 61px; height: 17px">
21
性 别:</td>
22
<td style="width: 139px; height: 17px;">
23
<asp:Label ID="Label4" runat="server"><%# DataBinder.Eval(Container.DataItem,"sex") %></asp:Label></td>
24
</tr>
25
<tr>
26
<td style="width: 61px; height: 18px">
27
年 龄:</td>
28
<td style="width: 78px; height: 18px">
29
<asp:Label ID="Label2" runat="server"><%# DataBinder.Eval(Container.DataItem,"age") %></asp:Label></td>
30
<td style="width: 61px; height: 18px">
31
出生日期:</td>
32
<td style="width: 139px; height: 18px">
33
<asp:Label ID="Label3" runat="server"><%# DataBinder.Eval(Container.DataItem,"date") %></asp:Label></td>
34
</tr>
35
<tr>
36
<td style="width: 61px">
37
政治面貌:</td>
38
<td style="width: 78px">
39
<asp:Label ID="Label5" runat="server"><%# DataBinder.Eval(Container.DataItem,"govement") %></asp:Label></td>
40
<td style="width: 61px">
41
家庭住址:</td>
42
<td style="width: 139px">
43
<asp:Label ID="Label7" runat="server"><%# DataBinder.Eval(Container.DataItem,"address") %></asp:Label></td>
44
</tr>
45
<tr>
46
<td style="width: 61px">
47
联系电话:</td>
48
<td style="width: 78px">
49
<asp:Label ID="Label6" runat="server"><%# DataBinder.Eval(Container.DataItem,"phone") %></asp:Label></td>
50
<td style="width: 61px">
51
QQ:</td>
52
<td style="width: 139px">
53
<asp:Label ID="Label8" runat="server"><%# DataBinder.Eval(Container.DataItem,"qq") %></asp:Label></td>
54
</tr>
55
</table>
56
<br />
57
</ItemTemplate>
58
<HeaderTemplate>
59
职员信息
60
</HeaderTemplate>
61
</asp:DataList></div>
62
</form>
63
</body>
64
</html>
65

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

index.aspx.cs代码如下:
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Web;
5
using System.Web.Security;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
using System.Web.UI.WebControls.WebParts;
9
using System.Web.UI.HtmlControls;
10
using System.Data.SqlClient;
11
12
public partial class _Default : System.Web.UI.Page
13
{
14
protected void Page_Load(object sender, EventArgs e)
15
{
16
if (!IsPostBack)
17
{
18
string strCon = "Data Source=(local); Database=db_02;Uid=sa;Pwd=123456";
19
SqlConnection sqlcon = new SqlConnection(strCon);
20
string sqlstr = "select top 2* from tb_Employee";
21
SqlDataAdapter myda = new SqlDataAdapter(sqlstr,sqlcon);
22
DataSet myds = new DataSet();
23
sqlcon.Open();
24
myda.Fill(myds);
25
DataList1.DataSource = myds;
26
DataList1.DataBind();
27
sqlcon.Close();
28
}
29
}
30
}
31

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31
