10月 02, 2006

最近在學寫ASP.net,感覺不錯!
不過既然datagrid有支援分頁怎麼datalist不順便支援?
流程是Sqldatasource控制項→PagedDataSource控制項→DataList控制項
參考"廖瑞奇站長的文章-用Repeater分頁"撰寫以下程式

範例:http://vip.blueshop.com.tw/joehwang/flower/default.aspx
下載:http://joehwang.myweb.hinet.net/xuite/page_datalist.zip


default.aspx



detail.aspx
  
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim id As Integer
id = Request.QueryString("id")

Dim db1 As New SqlDataSource
db1.ProviderName = "System.Data.OleDb"
db1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|flower.mdb;"
db1.SelectCommand = "select * from [flowers_plants] where fp_id= ? "
db1.SelectParameters.Add("fp_id", id)
Dim dv As Data.DataView = db1.Select(New DataSourceSelectArguments)
Me.FormView1.DataSource = dv

Me.FormView1.DataBind()
End Sub


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>未命名頁面</title>
</head>
<body>
<form id="form1" runat="server">
<div align=center>
<asp:FormView ID="FormView1" runat="server" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical">
<ItemTemplate>

<img src=small/<%# DataBinder.Eval(Container.DataItem, "s_file") %> /><br />
ID:
<asp:Label ID="fp_idLabel" runat="server" Text='<%# Bind("fp_id") %>'></asp:Label><br />
名稱:
<asp:Label ID="c_nameLabel" runat="server" Text='<%# Bind("c_name") %>'></asp:Label><br />
學名:
<asp:Label ID="e_nameLabel" runat="server" Text='<%# Bind("e_name") %>'></asp:Label><br />
家族:
<asp:Label ID="familyLabel" runat="server" Text='<%# Bind("family") %>'></asp:Label><br />
別名:
<asp:Label ID="aliasLabel" runat="server" Text='<%# Bind("alias") %>'></asp:Label><br />
科名:
<asp:Label ID="scientific_nameLabel" runat="server" Text='<%# Bind("scientific_name") %>'>
</asp:Label><br />
類別
<asp:Label ID="classLabel" runat="server" Text='<%# Bind("class") %>'></asp:Label><br />

</ItemTemplate>
<FooterStyle BackColor="#CCCC99" />
<EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F7DE" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />


</asp:FormView>

</div>
</form>
</body>
</html>





沒有留言: