ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
[我的ASP.net学习历程]DataGrid(PageChange)(1)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

<%@ 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&nbsp;
 <asp:radiobutton ID="Radio_2" GroupName="Style" runat="server"/>Text<p/>&nbsp;
 <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>




相关文章

相关软件