您的位置:首页 > 其它

最近看 DataList 的使用方法感觉好郁闷。

2006-11-08 16:32 288 查看
DataList 使用的方法

1。这个是MSDN上面的,没有取库中的数据绑定,而是自己申明了一个 DataTable 进行绑定的
前台代码:

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>DataList 测试</title>
8</head>
9<body>
10 <form id="form1" runat="server">
11 <div style="text-align: center">
12 <asp:DataList ID="ItemDataList" runat="server" RepeatColumns="3" Width="288px">
13 <ItemTemplate>
14 <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("image") %>'/>
17 </ItemTemplate>
18 </asp:DataList> </div>
19 </form>
20</body>
21</html>
22

后台代码:

using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class dataList1 : System.Web.UI.Page
13

2。这个是thcjp.cnblogs.com 的一个留言本,学习了一下,记下学习代码
前台:book.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="book.aspx.cs" Inherits="book" %>
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>无标题页</title>
8 <style type="text/css">
9 </style>
13</head>
14<body>
15 <form id="form1" runat="server">
16 <div style="text-align: center">
17 <asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound" Width="120px">
18 <ItemTemplate>
19 <table border="1" style="width: 614px">
20 <tr>
21 <td style="width: 153px; background-color: #ccff66; height: 27px;">
22 <asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label></td>
23 <td style="width: 369px; text-align: left; height: 27px; background-color: #ccccff;">
24 <asp:Label ID="Label2" runat="server" Text='<%# Server.HtmlDecode(Eval("title").ToString()) %>'></asp:Label></td>
25 <td style="width: 100px; height: 27px; background-color: #cccc66;">
26 <a href='huifu.aspx?id=<%# Eval("id")%>'><asp:Image ID="Image1" runat="server" ImageUrl="~/images/quote.gif" ToolTip='回复' /></a></td>
27 </tr>
28 <tr>
29 <td style="width: 153px; height: 84px;" valign="top">
30 <br />
31 <asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("face") %>' /><br />
32 <br />
33 <asp:Image ID="Image7" runat="server" ImageUrl="~/images/icon_qq.gif" ToolTip='<%# Eval("qq") %>' />
34 <asp:Image ID="Image3" runat="server" ImageUrl="~/images/icon_mail.gif" ToolTip='<%# Eval("email") %>' />
35 <asp:Image ID="Image4" runat="server" ImageUrl="~/images/icon_msn.gif" ToolTip='<%# Eval("msn") %>' />
36 <asp:Image ID="Image5" runat="server" ImageUrl="~/images/icon_homepage.gif" ToolTip='<%# Eval("url") %>' />
37 <asp:Image ID="Image6" runat="server" ImageUrl="~/images/icon_ip.gif" ToolTip='<%# Eval("ip") %>' /> 
38 <br />
39 <br />
40 <asp:Label ID="Label4" runat="server" Text='<%# Eval("dtt") %>'></asp:Label>
41 </td>
42 <td style="text-align: left; height: 84px;" colspan="2" valign="top">
43 <br />
44 <asp:Label ID="Label3" runat="server" Text='<%# Server.HtmlDecode(Eval("concent").ToString()) %>'></asp:Label><br />
45 <asp:Panel ID="dl" runat="server" Height="50px" Visible="False" Width="350px">
46 请输入密码<br />
47 <asp:TextBox ID="dlpwd" runat="server" Width="120px"></asp:TextBox>
48 <asp:Button ID="button1" runat="server" Text="查看留言" OnClick="button1_Click" />
49 <br />
50 <asp:Label ID="iidd" runat="server" Text='<%# Eval("id") %>' Visible="False"></asp:Label><br />
51 </asp:Panel>
52 <asp:Panel ID="Panel2" runat="server" Height="50px" Visible="False" Width="350px">
53 ==============回复内容==================<br />
54 <asp:DataList ID="DataList2" runat="server">
55 <ItemTemplate>
56 <table border="1" style="width: 335px">
57 <tr>
58 <td style="width: 100px; background-color: #99cccc; height: 20px;">
59 <asp:Label ID="Label6" runat="server" Text='<%# Eval("title") %>'></asp:Label>
60 (<asp:Label ID="Label7" runat="server" Text='<%# Eval("dtt","{0:d}") %>'></asp:Label>)</td>
61 </tr>
62 <tr>
63 <td style="width: 100px; background-color: #99cccc">
64 <asp:Label ID="Label8" runat="server" Text='<%# Server.HtmlDecode(Eval("concent").ToString()) %>'></asp:Label></td>
65 </tr>
66 </table>
67 </ItemTemplate>
68 </asp:DataList></asp:Panel>
69 </td>
70 </tr>
71 </table>
72 </ItemTemplate>
73 </asp:DataList><br />
74 <table border="1" style="width: 606px; height: 63px">
75 <tr>
76 <td style="width: 50%">
77 </td>
78 <td>
79 <asp:LinkButton ID="pageup" runat="server" OnClick="pageup_Click">上一页</asp:LinkButton>
80 <asp:DropDownList ID="pageddl" runat="server" AutoPostBack="True" OnSelectedIndexChanged="pageddl_SelectedIndexChanged">
81 </asp:DropDownList>
82 <asp:LinkButton ID="pagedown" runat="server" OnClick="pagedown_Click">下一页</asp:LinkButton>
83 <asp:Label ID="pagelbl" runat="server" Text="1" Visible="False"></asp:Label></td>
84 </tr>
85 </table>
86 <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/book.mdb"
87 SelectCommand="SELECT * FROM [guest]"></asp:AccessDataSource>
88
89 </div>
90 </form>
91</body>
92</html>
93

后台:book.aspx.cs

using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class book : System.Web.UI.Page
13
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐