asp.net 源码保存 用程序分页(2)


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
recordCount = page.RetrieveDataCount();
totalPages = (int)(Math.Ceiling((double)recordCount / (double)page.PageSize));
if (!IsPostBack)
{
BindData();
}
}
Alex.PageTools page = new Alex.PageTools("Test", "*", "1=1", "USER_Account", false, "USER_Account", 10, 1, null);
int recordCount;
public int totalPages;

private void BindData()
{
int pageIndex = SmartGridView1.PageIndex;
if(totalPages>0)
{
if(pageIndex>totalPages-1)
{
pageIndex=totalPages-1;
}
}
else
{
pageIndex=0;
}
SmartGridView1.PageIndex=pageIndex;
page.PageIndex=pageIndex+1;
SmartGridView1.DataSource = page.RetrievePagerData();
SmartGridView1.DataBind();
if (this.SmartGridView1.PageIndex == 0)
{
this.btnFirst.Enabled = false;
this.btnPrev.Enabled = false;
if (totalPages == 1)
{
this.btnLast.Enabled = false;
this.btnNext.Enabled = false;
}
}
else if (this.SmartGridView1.PageIndex == totalPages - 1)
{
this.btnLast.Enabled = false;
this.btnNext.Enabled = false;
}
this.lblpagesum.Text = totalPages.ToString();
this.lblpage.Text = (pageIndex + 1).ToString();
this.lblrowscount.Text = recordCount.ToString();
}
public void NavigateToPage(object sender, CommandEventArgs e)
{
btnFirst.Enabled = true;
btnPrev.Enabled = true;
btnNext.Enabled = true;
btnLast.Enabled = true;
string pageinfo = e.CommandArgument.ToString();
switch (pageinfo)
{
case "Prev":
if (this.SmartGridView1.PageIndex > 0)
{
this.SmartGridView1.PageIndex -= 1;
}
break;
case "Next":
if (this.SmartGridView1.PageIndex < (totalPages - 1))
{
this.SmartGridView1.PageIndex += 1;
}
break;
case "First":
this.SmartGridView1.PageIndex = 0;
break;
case "Last":
this.SmartGridView1.PageIndex = totalPages - 1;
break;
}
if (this.SmartGridView1.PageIndex == 0)
{
btnFirst.Enabled = false;
btnPrev.Enabled = false;
if (totalPages == 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
}
}
else if (this.SmartGridView1.PageIndex == totalPages - 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
}
BindData();
}
protected void gobtnClick(object sender, EventArgs e)
{
int goPageIndex = Convert.ToInt32(this.goCount.Text.Trim());
if (goPageIndex > 0)
{
if (goPageIndex >= totalPages)
{
this.SmartGridView1.PageIndex = totalPages - 1;
}
else
{
this.SmartGridView1.PageIndex = goPageIndex - 1;
}
}
else if(goPageIndex <=0)
{
this.SmartGridView1.PageIndex = 0;
}
if (this.SmartGridView1.PageIndex == 0)
{
btnFirst.Enabled = false;
btnPrev.Enabled = false;
btnLast.Enabled = true;
btnNext.Enabled = true;
if (totalPages == 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
}
}
else if (this.SmartGridView1.PageIndex == totalPages - 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
btnFirst.Enabled = true;
btnPrev.Enabled = true;
}
else
{
btnLast.Enabled = true;
btnFirst.Enabled = true;
btnNext.Enabled = true;
btnPrev.Enabled = true;
}
BindData();
}


页面前台:

代码

复制代码 代码如下:


<%@ Page Language="C#" Theme="msn_blue" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="SmartGridView" Namespace="BOSSWWebUI.SmartGridView" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script type="text/javascript">
function validate() {
var gocount=document.getElementById("goCount").value;
if(gocount=="")
{
alert("请先填写你要导航的页面");
return false;
}
var result;
if(isNaN(gocount))
{
alert("请输入合法的数字");
document.getElementById("goCount").value="";
return false;
}
if(parseInt(gocount)<=0|| parseInt(gocount)><%=this.totalPages %>)
{
alert("数字溢出");
document.getElementById("goCount").value="";
return false;
}
return true;
}
</script>
<form runat="server">
<div>
<table cellspacing="0" cellpadding="0">
<tr runat="server">
<td>
○ 页次:<asp:Label runat="server" ></asp:Label>/
<asp:Label runat="server"></asp:Label>,共:<asp:Label
ID="lblrowscount" runat="server"></asp:Label>条</td>
<td>
<asp:LinkButton runat="server" OnCommand="NavigateToPage"
CommandArgument="First" CommandName="Pager" Text="首 页">[首 页]</asp:LinkButton><asp:LinkButton
ID="btnPrev" runat="server" CommandArgument="Prev" OnCommand="NavigateToPage"
CommandName="Pager" Text="上一页">[上一页]</asp:LinkButton><asp:LinkButton
runat="server" CommandArgument="Next" OnCommand="NavigateToPage"
CommandName="Pager" Text="下一页">[下一页]</asp:LinkButton><asp:LinkButton
runat="server" CommandArgument="Last" OnCommand="NavigateToPage"
CommandName="Pager" Text="尾 页" >[尾 页]</asp:LinkButton>
<asp:TextBox ID=goCount runat="server"></asp:TextBox>
<asp:Button runat="server" Text="go" OnClientClick="return validate();" /></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0">
<tr>
<td>
<uc1:SmartGridView SkinID="blue" runat="server"
PagingStyle="Default"
CssClassMouseOver="grid_over" EnableViewState="False"
AutoGenerateColumns="False"
Width="100%" currentLanguage="">
<Columns>
<asp:TemplateField>
<headertemplate>
<asp:checkbox runat="server" />
</headertemplate>
<itemtemplate>
<asp:checkbox runat="server" __designer:wfdid="w1"></asp:checkbox>
</itemtemplate>
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:TemplateField>
<asp:BoundField DataField="USER_Account" HeaderText="用户帐号" SortExpression="USER_Account">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_DspName" HeaderText="显示名称" SortExpression="USER_DspName">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_DspEngName" HeaderText="英文名" SortExpression="USER_DspEngName" >
<headerstyle cssclass="tdcell" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
<asp:BoundField DataField="USER_HRID" HeaderText="员工号" SortExpression="USER_HRID" >
<headerstyle cssclass="tdcell" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
<asp:BoundField DataField="USER_Email" HeaderText="邮件地址" SortExpression="USER_Email">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Title" HeaderText="职 称" SortExpression="USER_Title">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Tel" HeaderText="电 话" SortExpression="USER_Tel">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Active" HeaderText="是否有效" SortExpression="USER_Active">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Major" HeaderText="专业" SortExpression="USER_Major" >
<headerstyle cssclass="tdcell" horizontalalign="Center" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
</Columns>
<HeaderStyle CssClass="thHead" />
<FixRowCol TableHeight="" TableWidth="" />
<RowStyle CssClass="tdcell" />
</uc1:SmartGridView>
</td></tr>
</table>
</div>
</form>
</body>
</html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjjjgg.html