<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>
<script language="C#" runat="server">
public DataTable NowUseSource;//传递至Datalist的来源
public DataTable NowSource ;//复制一条记录的来源
public string NowDataList;//目前使用的Datalist名称
public Boolean FirstUse;//是否为第一次加载
	public int NowRecord{//设定及返回目前条数
		get{
			return Convert.ToInt32(CurrentRecord.Text);
		}
		set{
			CurrentRecord.Text = value.ToString();
		}
	}
	public int AllRecord{//设定及返回所有条数
		get{
			return Convert.ToInt32(AllRecords.Text);
		}
		set{
			AllRecords.Text = value.ToString();
		}
	}
	public string NowStatus{//设定及返回目前状态
		get{
			return Status.Text;
		}
		set{
			Status.Text = value.ToString();
		}
	}
	void ChangeRecord(object sender,CommandEventArgs e){//切换记录
		if(e.CommandArgument == "Next"){
			if(Convert.ToInt32(CurrentRecord.Text) < Convert.ToInt32(AllRecords.Text)){
				ShowRecord(Convert.ToInt32(CurrentRecord.Text)+1);
				CurrentRecord.Text=(Convert.ToInt32(CurrentRecord.Text)+1).ToString();
			}
		}
		else if(e.CommandArgument == "First"){
			ShowRecord(1);
			CurrentRecord.Text="1";
		}
		else if(e.CommandArgument == "Last"){
			CurrentRecord.Text=AllRecords.Text;
			ShowRecord(Convert.ToInt32(AllRecords.Text) - 1);
		}
		else if(e.CommandArgument == "Prev"){
			if(Convert.ToInt32(CurrentRecord.Text) > 1){
				CurrentRecord.Text=(Convert.ToInt32(CurrentRecord.Text) - 1).ToString();
				ShowRecord(Convert.ToInt32(CurrentRecord.Text));
			}
		}
	}
	public void ShowRecord(int RecordNumber){//显示记录
		if(FirstUse == true){//若第一次载入
			Session["NowUseSource"]=NowUseSource;
			Session["NowSource"]=NowSource;
			Session["NowDataList"]=NowDataList;
		}
		else{
			NowUseSource=(DataTable)Session["NowUseSource"];
			NowSource=(DataTable)Session["NowSource"];
			NowDataList=Session["NowDataList"].ToString();
		}
		NowUseSource.Rows.Clear();//清除所有记录
		DataRow NowRow = NowSource.Rows[RecordNumber-1];//取得将导入的记录
		NowUseSource.ImportRow(NowRow);//导入
		DataList m = (DataList)Page.FindControl(NowDataList);
		m.DataSource=NowUseSource.DefaultView;
		m.DataBind();
		Session["NowUseSource"]=NowUseSource;
	}
	void Gotorecord(object sender, EventArgs e){//到
		if(Convert.ToInt32(ToRecord.Text) < Convert.ToInt32(AllRecords.Text)){
			CurrentRecord.Text=ToRecord.Text;
			ShowRecord(Convert.ToInt32(CurrentRecord.Text));
		}
		ToRecord.Text = "";
	}
	</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>