asp.net (c#) MySQL 大数据快速分页
2009-10-16 10:07
483 查看
aspx页: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" CssClass="b"> <asp:ListItem Value="5">5 per page</asp:ListItem> <asp:ListItem Selected="True" Value="10">10 per page</asp:ListItem> <asp:ListItem Value="50">50 per page</asp:ListItem> </asp:DropDownList> --每页显示条数 <asp:Label ID="lbpageof" runat="server"></asp:Label> --显示方式 <asp:LinkButton ID="lbpre" runat="server" CommandArgument="prev" OnClick="PagerButtonClick">Previous</asp:LinkButton> --前一页 <asp:LinkButton ID="lbnext" runat="server" CommandArgument="next" OnClick="PagerButtonClick">Next</asp:LinkButton> --后一页 <asp:LinkButton ID="lbpre2" runat="server" CommandArgument="prev" OnClick="PagerButtonClick">Previous</asp:LinkButton> --前一页2 <asp:LinkButton ID="lbnext2" runat="server" CommandArgument="next" OnClick="PagerButtonClick">Next</asp:LinkButton> --后一页2 <input id="hid_CurrentIndex" runat="server" type="hidden" /> --索引数 cs: hid_CurrentIndex.Value = "0"; 初始化为0 首先给出_sqlStr(sql语句) DataSet ds; 通过程序得到一个(ds)Dataset ds = _db.GetDataSet(_sqlStr + " limit " + (Convert.ToInt64(hid_CurrentIndex.Value) * Convert.ToInt64(DropDownList1.SelectedValue)) + "," + DropDownList1.SelectedValue); --DropDownList1.SelectedValue1的值为每页显示条数 GridView1.PageSize = 10; GridView1.DataSource = ds.Tables[0].DefaultView; GridView1.DataBind(); linkbttonenableset(); private void linkbttonenableset() { try { double dblTotalRecords = Convert.ToDouble(取得总的记录行数单独写个sql_count); double dblPageRecords = Convert.ToDouble(DropDownList1.SelectedValue); --每页显示行数 double dbltemp1 = dblTotalRecords / dblPageRecords; double dbltemp2 = (double)((long)(dblTotalRecords / dblPageRecords)); long lngShowPages = 0; if(dbltemp1 == dbltemp2) { lngShowPages = (long)dbltemp1; } else { lngShowPages = (long)(dbltemp1+1); } lbpageof.Text = "Displaying " + (Convert.ToInt64(hid_CurrentIndex.Value.Trim()) + 1) + " of " + lngShowPages.ToString("###,###"); lbnext.Text = "Next " + DropDownList1.SelectedItem.Value; lbpre.Text = "Previous " + DropDownList1.SelectedItem.Value; lbnext2.Text = "Next " + DropDownList1.SelectedItem.Value; lbpre2.Text = "Previous " + DropDownList1.SelectedItem.Value; lbpageof.Visible = true; lbnext.Enabled = true; lbpre.Enabled = true; lbnext2.Enabled = true; lbpre2.Enabled = true; if (GridView1.Rows.Count == 0) { lbpageof.Visible = false; lbnext.Enabled = false; lbpre.Enabled = false; lbnext2.Enabled = false; lbpre2.Enabled = false; } if (((Convert.ToInt64(hid_CurrentIndex.Value.Trim()) + 1) * Convert.ToInt64(DropDownList1.SelectedValue)) > Convert.ToInt64(lbrecords.Text.Trim ().Replace(",", "").Replace("Records: ", ""))) { lbnext.Enabled = false; lbnext2.Enabled = false; } if ((hid_CurrentIndex.Value == "0") || (((Convert.ToInt64(hid_CurrentIndex.Value.Trim()) + 1) * Convert.ToInt64(DropDownList1.SelectedValue)) - Convert.ToInt16(DropDownList1.SelectedValue.Trim()) < 0)) { lbpre.Enabled = false; lbpre2.Enabled = false; } } catch (Exception ex) { lbpageof.Visible = false; lbnext.Enabled = false; lbpre.Enabled = false; lbnext2.Enabled = false; lbpre2.Enabled = false; } } protected void PagerButtonClick(object sender, EventArgs e) { string arg = ((LinkButton)sender).CommandArgument.ToString(); switch (arg) { case "prev": hid_CurrentIndex.Value = Convert.ToString(Convert.ToInt64(hid_CurrentIndex.Value) - 1); break; case "next": hid_CurrentIndex.Value = Convert.ToString(Convert.ToInt64(hid_CurrentIndex.Value) + 1); break; default: hid_CurrentIndex.Value = ""; break; } gridviewshow(sqlStr); --重新取得sql得到得到新的hid_CurrentIndex.Value得到新的dataset } protected void PagerButtonClick(object sender, EventArgs e) { string arg = ((LinkButton)sender).CommandArgument.ToString(); switch (arg) { case "prev": hid_CurrentIndex.Value = Convert.ToString(Convert.ToInt64(hid_CurrentIndex.Value) - 1); break; case "next": hid_CurrentIndex.Value = Convert.ToString(Convert.ToInt64(hid_CurrentIndex.Value) + 1); break; default: hid_CurrentIndex.Value = ""; break; } gridviewshow(sqlStr); --重新取得sql得到得到新的hid_CurrentIndex.Value得到新的dataset } --其他按钮省略 意思一样
相关文章推荐
- asp.net(c#)快速生成Json格式的数据(JsonHelper)
- 在ASP.Net With C# 中使用 DataGrid 控件分页展示数据
- asp.net(c#)快速生成Json格式的数据(JsonHelper)
- ASP.NET(C#)SqlBulkCopy批量的快速插入数据
- C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 大数据分页功能改进、数据权限改进
- C# asp.net页面接收的数据保存到Txt文件中, C#将数据保存到记录本中 conquer
- ASP.NET(五):ASP.net实现真分页显示数据
- asp.net(c#)如何读取上传过程中的.txt文件中的数据,并将其写入数据库的
- asp.net mvc jqgrid 同一个页面查询不同的表,jqgrid显示不同表的表头和数据并且分页
- ASP.NET调用oracle存储过程实现快速分页
- ASP.NET网站权限设计实现(三)——套用JQuery EasyUI列表显示数据、分页、查询
- Scott Mitchell 的ASP.NET 2.0数据教程之二十五:: 大数据量时提高分页的效率
- 同事间闲聊,如何成为优秀架构师?如何才能快速能成为C#ASP.NET开发高手?
- asp.net(C#)连接xml,显示数据。
- ASP.NET C#+Ajax+json无刷新分页参考
- ASP.net 2.0 自定义控件的开发之数据分页 第五章
- 如何使用 ASP.NET、ADO.NET 和 Visual C# .NET 查询和显示 Excel 数据
- 【C#.NET】ASP.NET 2.0 数据绑定概述(转)
- C# ASP.NET AspNetPager对DataList控件分页