<%@ Page Language="C#" AutoEventWireup="True" Debug="true" %>
<Script language="C#" runat="server">
void Page_Load(Object Sender,EventArgs e){
//页面初始化
if (!Page.IsPostBack){
PageSize.Text="10";
PageIndex.Text="0";
NumberPage.Checked=true;
MyDataGrid.CurrentPageIndex=0;
MyDataGrid.PageSize=15;
MyDataGrid.PagerStyle.Mode=PagerMode.NumericPages;
}
DataSource(); //函数调用
}
//数据源
void DataSource(){
Hashtable HT=new Hashtable();
HT.Add("12345","Microft");
HT.Add("56789","Imndkksdf");
HT.Add("9856","lsdjflksjdl");
HT.Add("6345646","lskjdflksjdlkfjslkdf");
HT.Add("3463","sdvsdgsrgsdf");
HT.Add("23","wfgdfhdfjfj");
HT.Add("63456443256","kuyoghjfg");
HT.Add("2214","eyeryh");
HT.Add("6546456","rutykhfg");
HT.Add("67567","wwryerhh");
HT.Add("442","fjfgj");
HT.Add("2345436","nbmbm");
HT.Add("235346","fghfgn");
HT.Add("567567568","sdgsdtewt");
HT.Add("567","hyjgh");
HT.Add("3453456",",jhluyk");
HT.Add("945434553","rtyfdhfd");
HT.Add("34634","ewerygthtjyjtyiktyktyk");
MyDataGrid.DataSource=HT;
MyDataGrid.DataBind();
}
//页页变化函数
void PageChange(Object Sender,DataGridPageChangedEventArgs E){
MyDataGrid.CurrentPageIndex=E.NewPageIndex;
MyDataGrid.DataBind();
}
//以数子做为换页函数
void NumberPageClick(Object Sender,EventArgs E){
FontsPage.Checked=false;
MyDataGrid.PagerStyle.Mode=PagerMode.NumericPages;
DataSource();
}
//以字符做为换页函数
void FontsPageClick(Object Sender,EventArgs E){
NumberPage.Checked=false;
MyDataGrid.PagerStyle.Mode=PagerMode.NextPrev;
MyDataGrid.PagerStyle.NextPageText="Next";
MyDataGrid.PagerStyle.PrevPageText="Prev";
DataSource();
}
//页面索引函数
void IndexClick(Object Sender,EventArgs E){
MyDataGrid.CurrentPageIndex=Int32.Parse(PageIndex.Text);
DataSource();
}
//每页显示多少行函数
void SizeClick(Object Sender,EventArgs E){
MyDataGrid.PageSize=Int32.Parse(PageSize.Text);
DataSource();
}
</Script>
<form runat="server">
<asp:datagrid ID="MyDataGrid" AutoGenerateColumns="false" Width="100%" runat="server" AllowPaging="true" PagerStyle-HorizontalAlign="Right" HeaderStyle-BackColor="#FF9900" PagerStyle-BackColor="#FF9900" ItemStyle-BackColor="#FFCC00" AlternatingItemStyle-BackColor="#FFFF00" OnPageIndexChanged="PageChange">
<columns>
<asp:boundcolumn DataField="Key" HeaderText="<strong>Number</strong>"></asp:boundcolumn>
<asp:boundcolumn DataField="Value" HeaderText="<strong>Value</strong>"></asp:boundcolumn>
</columns>
</asp:datagrid>
PageIndex:
<asp:textbox ID="PageIndex" runat="server"/>
<asp:button ID="Button_1" Text="GoIndex" OnClick="IndexClick" runat="server"/><br>
PageSize:
<asp:textbox ID="PageSize" runat="server"/>
<asp:button ID="Button_2" Text="GoSize" OnClick="SizeClick" runat="server"/><br>
PagerMode:
<asp:radiobutton ID="NumberPage" OnCheckedChanged="NumberPageClick" AutoPostBack="true" Text="Number" runat="server"/>
<asp:radiobutton ID="FontsPage" OnCheckedChanged="FontsPageClick" AutoPostBack="true" Text="Fonts" runat="server"/>
</form>
本文地址:http://com.8s8s.com/it/it8582.htm