<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>
<script language="VB" runat="server">
public NowUseSource as DataTable'传递至Datalist的来源
public NowSource as DataTable '复制一条记录的来源
public NowDataList as string '目前使用的Datalist名称
public FirstUse as Boolean'是否为第一次载入
	public Property NowRecord() as Integer'设定及返回目前条数
		Get
			return Convert.ToInt32(CurrentRecord.Text)
		End Get
		Set
			CurrentRecord.Text = value.ToString()
		End Set
	end Property
	public Property AllRecord() as Integer '设定及返回所有条数
		get
			return Convert.ToInt32(AllRecords.Text)
		end get
		set
			AllRecords.Text = value.ToString()
		end set
	end property
	public property NowStatus() as string'设定及返回目前状态
		get
			return Status.Text
		end get
		set
			Status.Text = value.ToString()
		end set
	end property
	sub ChangeRecord(sender as object,e as CommandEventArgs)'切换记录
		if e.CommandArgument = "Next" then
			if Convert.ToInt32(CurrentRecord.Text) < Convert.ToInt32(AllRecords.Text) then
				ShowRecord(Convert.ToInt32(CurrentRecord.Text)+1)
				CurrentRecord.Text=(Convert.ToInt32(CurrentRecord.Text)+1).ToString()
			end if
		elseif e.CommandArgument = "First" then
			ShowRecord(1)
			CurrentRecord.Text="1"
		elseif e.CommandArgument = "Last" then
			CurrentRecord.Text=AllRecords.Text
			ShowRecord(Convert.ToInt32(AllRecords.Text) - 1)
		elseif e.CommandArgument = "Prev" then
			if Convert.ToInt32(CurrentRecord.Text) > 1 then
				CurrentRecord.Text=(Convert.ToInt32(CurrentRecord.Text) - 1).ToString()
				ShowRecord(Convert.ToInt32(CurrentRecord.Text))
			end if
		end if
	end sub
	public sub ShowRecord(RecordNumber as integer)'显示记录
		if FirstUse = true then'若第一次载入
			Session("NowUseSource")=NowUseSource
			Session("NowSource")=NowSource
			Session("NowDataList")=NowDataList
		else
			NowUseSource=Ctype(Session("NowUseSource"),DataTable)
			NowSource=Ctype(Session("NowSource"),DataTable)
			NowDataList=Session("NowDataList").ToString()
		end if
		NowUseSource.Rows.Clear()'清除所有记录
		Dim NowRow as DataRow = NowSource.Rows(RecordNumber-1)'取得将汇入的记录
		NowUseSource.ImportRow(NowRow)'汇入
		Dim m as DataList = Ctype(Page.FindControl(NowDataList),DataList)
		m.DataSource=NowUseSource.DefaultView
		m.DataBind()
		Session("NowUseSource")=NowUseSource
	end sub
	sub Gotorecord(sender as object,e as EventArgs)'到
		if Convert.ToInt32(ToRecord.Text) < Convert.ToInt32(AllRecords.Text) then
			CurrentRecord.Text=ToRecord.Text
			ShowRecord(Convert.ToInt32(CurrentRecord.Text))
		end if
		ToRecord.Text = ""
	end sub
	</script>
<asp:LinkButton ID="First" Tooltip="First" OnCommand="ChangeRecord" Runat="server" Text="首条" CommandArgument="First" />
<asp:LinkButton ID="Prev" Tooltip="Prev" OnCommand="ChangeRecord" Runat="server" Text="上条" CommandArgument="Prev" />
<asp:LinkButton ID="Next" Tooltip="Next" OnCommand="ChangeRecord" Runat="server" Text="下条" CommandArgument="Next" />
<asp:LinkButton ID="Last" Tooltip="Last" OnCommand="ChangeRecord" Runat="server" Text="末条" CommandArgument="Last" />
至第<asp:TextBox Columns="3" AutoPostBack="true" OnTextChanged="Gotorecord" ID="ToRecord" Runat="server" />条　
<p>第<asp:Label ID="CurrentRecord" Tooltip="CurrentRecord" Runat="server" />条，共<asp:Label ID="AllRecords" Text=<%# AllRecord %> Tooltip="AllRecords" Runat="server" />条　　
<font color="#FF0000"><b>目前状态：<asp:label id="Status" Tooltip="Status" runat="server" /></b></font>
<asp:label id="nn" runat="server" />
<hr>