<%@ Page Language="VB" Debug ="true" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xHtml1-transitional.dtd">
<script runat="server">
Dim connstr As String
Dim sql As String
Dim mycommand As OleDbCommand
Dim myread As OleDbDataReader
Dim conn As OleDbConnection
Sub page_load(ByVal sender As Object, ByVal e As EventArgs)
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("rizhi.mdb") & ";User Id=;PassWord=;"
conn = New OleDbConnection(connstr)
conn.Open()
sql = "select * from rizhi"
mycommand = New OleDbCommand(sql, conn)
myread = mycommand.ExecuteReader()
GridVIEw1.DataSource = myread
GridVIEw1.DataBind()
'Dim i As Integer
'Do While myread.Read()
' i = i + 1
'Loop
'Response.Write(i)
End Sub
</script>
<html XMLns="http://www.w3.org/1999/xHtml" >
<head runat="server">
<title>無標題頁</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<ASP:GridView ID="GridVIEw1" runat="server" AutoGenerateColumns="false" Width ="60%" Font-Size="12px" >
<Columns>
<ASP:BoundField DataFIEld="id" HeaderText="序號" >
<ItemStyle Font-Size="12px" HorizontalAlign="Left" />
<HeaderStyle BackColor="BurlyWood" Font-Size="12px" HorizontalAlign="Center" />
</ASP:BoundFIEld>
<ASP:BoundField DataFIEld="rq" HeaderText="日期" >
<ItemStyle Font-Size="12px" HorizontalAlign="Left" />
<HeaderStyle BackColor="BurlyWood" Font-Size="12px" HorizontalAlign="Center" />
</ASP:BoundFIEld>
<ASP:BoundField DataFIEld="n_je" HeaderText="金額" >
<ItemStyle Font-Size="12px" HorizontalAlign="Right" />
<HeaderStyle BackColor="BurlyWood" Font-Size="12px" HorizontalAlign="Center" />
</ASP:BoundFIEld>
<ASP:BoundField DataFIEld="title" HeaderText="標題" >
<ItemStyle Font-Size="12px" HorizontalAlign="Left" />
<HeaderStyle BackColor="BurlyWood" Font-Size="12px" HorizontalAlign="Center" />
</ASP:BoundFIEld>
<ASP:BoundField DataFIEld="content" HeaderText="內容" >
<ItemStyle Font-Size="12px" HorizontalAlign="Left" />
<HeaderStyle BackColor="BurlyWood" Font-Size="12px" HorizontalAlign="Center" />
</ASP:BoundFIEld>
<asp:HyperLinkField DataTextField="id" DataNavigateUrlFIElds ="id" DataNavigateUrlFormatString=" rizhi_edit.ASPx?id={0} " HeaderText ="操作" DataTextFormatString ="修改" >
<ItemStyle Font-Size="12px" HorizontalAlign="Center" />
<HeaderStyle BackColor ="burlyWood" Font-Size="12px" HorizontalAlign="center" />
</ASP:HyperLinkFIEld>
</Columns>
</ASP:GridVIEw>
</center>
</div>
</form>
</body>
</Html>
值得注意的是,這裡不光顯示了數據,而且還有一列是對數據的“操作”,當用戶點擊該列的時候,轉到修改頁面,並傳遞一個參數id,這裡傳遞參數的方法是 DataNavigateUrlFormatString="<% rizhi_edit.ASPx?id={0} %>" ,其中0表示第一個字段,1表示第二個字段,依此類推。