<%@ Page Language="C#" AutoEventWireup="True" Debug="true" %>
<Script language="C#" runat="server">
void Page_Load(Object Sender,EventArgs e){
if (!Page.IsPostBack){
TextBox_1.Text="Prev";
TextBox_2.Text="Next";
Radio_1.Checked=true;
TextBox_3.Text="4";
MyDataGrid.CurrentPageIndex=0; //起始索引值
BindDataGrid();
}
}
void BindDataGrid(){
ArrayList array=new ArrayList();
array.Add("MicroSoft");
array.Add("IBM");
array.Add("SUN");
array.Add("Live");
array.Add("MyLove");
array.Add("Jcksdklke");
array.Add("sdfsddcvds");
array.Add("35465132");
array.Add("css");
array.Add("VVVVVVV");
array.Add("WWWWWWW");
array.Add("ZZZZZZZZZZZ");
MyDataGrid.PageSize=Int32.Parse(TextBox_3.Text); //每页大小
if (Radio_1.Checked){
MyDataGrid.PagerStyle.Mode=PagerMode.NumericPages; //分页按钮显示模式-----以页数显示
}
else{
MyDataGrid.PagerStyle.Mode=PagerMode.NextPrev; //分页按钮显示模式------以上下页显示
}
MyDataGrid.PagerStyle.NextPageText=TextBox_2.Text; //分页按钮----上页
MyDataGrid.PagerStyle.PrevPageText=TextBox_1.Text; //分页按钮----下页
MyDataGrid.DataSource=array;
MyDataGrid.DataBind();
}
//页面索引变化函数
void ChangeGridPage(Object Sender,DataGridPageChangedEventArgs E){
MyDataGrid.CurrentPageIndex=E.NewPageIndex; //生成新页面索引
BindDataGrid();
}
</Script>
<form runat="server">
Previous Link Text:
<asp:textbox ID="TextBox_1" runat="server"/>
Next Link Text:
<asp:textbox ID="TextBox_2" runat="server"/><br>
Number of rows per Page:
<asp:textbox ID="TextBox_3" runat="server"/>
Paging Style:
<asp:radiobutton ID="Radio_1" GroupName="Style" runat="server"/>Numeric
<asp:radiobutton ID="Radio_2" GroupName="Style" runat="server"/>Text<p/>
<asp:datagrid ID="MyDataGrid" runat="server" Width="100%" AllowPaging="true" PagerStyle-HorizontalAlign="Right" OnPageIndexChanged="ChangeGridPage" AlternatingItemStyle-BackColor="#999999" ItemStyle-BackColor="#cccccc" HeaderStyle-BackColor="#555555" PagerStyle-BackColor="#555555" HeaderStyle-ForeColor="#FFFFFF" HeaderStyle-Font-Bold="true" PagerStyle-ForeColor="#FFFFFF"/>
</form>