Datalist分页代码
来源:互联网 发布:淘宝信誉排行榜 编辑:程序博客网 时间:2024/06/07 19:20
<%@ Page Language="c#" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Language="C#" runat="server">
int PageSize;
int RecordCoutn;
int pageCount;
int CurrentPage;
SqlConnection conn;
void Page_Load(object sender, EventArgs e)
...{
connOpen();
PageSize = 2;
if (!IsPostBack)
...{
mathBd();
CurrentPage = 0;
RecordCoutn=CalculateRecord();
this.lblRecordCount.Text=RecordCoutn.ToString();
pageCount = RecordCoutn / PageSize;
this.lblPageCount.Text = pageCount.ToString();
ViewState["PageIndex"] = 0;
ViewState["PageCount"] = pageCount;
DropDown();
}
}
private void connOpen()
...{
conn = new SqlConnection("server=ss/sqlexpress;database=Northwind;uid=sa;pwd=;");
conn.Open();
}
private void mathBd()
...{
int startIndex;
startIndex=PageSize*CurrentPage;
SqlDataAdapter sdr=new SqlDataAdapter ("select * from Employees",conn);
DataSet ds=new DataSet ();
sdr.Fill(ds,startIndex,PageSize,"Employees");
this.MyDataGrid.DataSource=ds.Tables["Employees"].DefaultView;
this.MyDataGrid.DataBind();
lbnFirstPage.Enabled = true;
lbnNextPage.Enabled = true;
lbnPrevPage.Enabled = true;
lbnLastPage.Enabled = true;
if (CurrentPage == (pageCount-1))
...{
lbnNextPage.Enabled = false;
lbnLastPage.Enabled = false;
}
if (CurrentPage == 0)
...{
lbnFirstPage.Enabled = false;
lbnPrevPage.Enabled = false;
}
this.Label2.Text = (CurrentPage + 1).ToString();
ViewState["PageIndex"] = CurrentPage;
}
public int CalculateRecord()
...{
int intRecord;
string strComm = "select count (*) as co from Employees";
SqlCommand comm = new SqlCommand(strComm, conn);
SqlDataReader dr = comm.ExecuteReader();
if (dr.Read())
...{
intRecord = Convert.ToInt32(dr["co"].ToString());
}
else
...{
intRecord = 0;
}
dr.Close();
return intRecord;
}
private void Page_OnClick(object sender, CommandEventArgs e)
...{
CurrentPage =(int) ViewState["PageIndex"];
pageCount=(int)ViewState["PageCount"];
string cmd = e.CommandName;
switch (cmd)
...{
case "next":
if (CurrentPage < (pageCount-1)) CurrentPage++; break;
case"prev":
if (CurrentPage > 0) CurrentPage--; break;
case"last":
CurrentPage = pageCount - 1; break;
default:
CurrentPage = System.Convert.ToInt32(cmd); break;
}
ViewState["PageIndex"] = CurrentPage;
//myDropDownList.SelectedIndex = CurrentPage;
mathBd();
}
private void DropDown()
...{
for (int u = 0; u < pageCount; u++)
...{
myDropDownList.Items.Add(new ListItem("第"+(u + 1).ToString() + "页", Convert.ToString(u)));
}
}
private void listchanged(object sender, EventArgs e)
...{
CurrentPage = myDropDownList.SelectedIndex;
mathBd();
}
</Script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Datalist 分页</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:DataList id="MyDataGrid" runat="server"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="Gainsboro"
EditItemStyle-BackColor="yellow"
>
<ItemTemplate>
姓名:<%# DataBinder.Eval(Container.DataItem,"EmployeeID") %>
</ItemTemplate>
</asp:DataList>
共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />条记录
当前为<asp:Label id="Label2" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server" />页
<br />
<hr />
<asp:LinkButton ID="lbnFirstPage" runat="server" CommandName="0" OnCommand="Page_OnClick">首页</asp:LinkButton>
<asp:LinkButton ID="lbnPrevPage" runat="server" CommandName="prev" OnCommand="Page_OnClick">上页</asp:LinkButton>
<asp:LinkButton ID="lbnNextPage" runat="server" CommandName="next" OnCommand="Page_OnClick">下页</asp:LinkButton>
<asp:LinkButton ID="lbnLastPage" runat="server" CommandName="last" OnCommand="Page_OnClick">未页</asp:LinkButton>
<asp:DropDownList ID="myDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="listchanged">
</asp:DropDownList>
</form>
</body>
</html>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Language="C#" runat="server">
int PageSize;
int RecordCoutn;
int pageCount;
int CurrentPage;
SqlConnection conn;
void Page_Load(object sender, EventArgs e)
...{
connOpen();
PageSize = 2;
if (!IsPostBack)
...{
mathBd();
CurrentPage = 0;
RecordCoutn=CalculateRecord();
this.lblRecordCount.Text=RecordCoutn.ToString();
pageCount = RecordCoutn / PageSize;
this.lblPageCount.Text = pageCount.ToString();
ViewState["PageIndex"] = 0;
ViewState["PageCount"] = pageCount;
DropDown();
}
}
private void connOpen()
...{
conn = new SqlConnection("server=ss/sqlexpress;database=Northwind;uid=sa;pwd=;");
conn.Open();
}
private void mathBd()
...{
int startIndex;
startIndex=PageSize*CurrentPage;
SqlDataAdapter sdr=new SqlDataAdapter ("select * from Employees",conn);
DataSet ds=new DataSet ();
sdr.Fill(ds,startIndex,PageSize,"Employees");
this.MyDataGrid.DataSource=ds.Tables["Employees"].DefaultView;
this.MyDataGrid.DataBind();
lbnFirstPage.Enabled = true;
lbnNextPage.Enabled = true;
lbnPrevPage.Enabled = true;
lbnLastPage.Enabled = true;
if (CurrentPage == (pageCount-1))
...{
lbnNextPage.Enabled = false;
lbnLastPage.Enabled = false;
}
if (CurrentPage == 0)
...{
lbnFirstPage.Enabled = false;
lbnPrevPage.Enabled = false;
}
this.Label2.Text = (CurrentPage + 1).ToString();
ViewState["PageIndex"] = CurrentPage;
}
public int CalculateRecord()
...{
int intRecord;
string strComm = "select count (*) as co from Employees";
SqlCommand comm = new SqlCommand(strComm, conn);
SqlDataReader dr = comm.ExecuteReader();
if (dr.Read())
...{
intRecord = Convert.ToInt32(dr["co"].ToString());
}
else
...{
intRecord = 0;
}
dr.Close();
return intRecord;
}
private void Page_OnClick(object sender, CommandEventArgs e)
...{
CurrentPage =(int) ViewState["PageIndex"];
pageCount=(int)ViewState["PageCount"];
string cmd = e.CommandName;
switch (cmd)
...{
case "next":
if (CurrentPage < (pageCount-1)) CurrentPage++; break;
case"prev":
if (CurrentPage > 0) CurrentPage--; break;
case"last":
CurrentPage = pageCount - 1; break;
default:
CurrentPage = System.Convert.ToInt32(cmd); break;
}
ViewState["PageIndex"] = CurrentPage;
//myDropDownList.SelectedIndex = CurrentPage;
mathBd();
}
private void DropDown()
...{
for (int u = 0; u < pageCount; u++)
...{
myDropDownList.Items.Add(new ListItem("第"+(u + 1).ToString() + "页", Convert.ToString(u)));
}
}
private void listchanged(object sender, EventArgs e)
...{
CurrentPage = myDropDownList.SelectedIndex;
mathBd();
}
</Script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Datalist 分页</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:DataList id="MyDataGrid" runat="server"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="Gainsboro"
EditItemStyle-BackColor="yellow"
>
<ItemTemplate>
姓名:<%# DataBinder.Eval(Container.DataItem,"EmployeeID") %>
</ItemTemplate>
</asp:DataList>
共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />条记录
当前为<asp:Label id="Label2" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server" />页
<br />
<hr />
<asp:LinkButton ID="lbnFirstPage" runat="server" CommandName="0" OnCommand="Page_OnClick">首页</asp:LinkButton>
<asp:LinkButton ID="lbnPrevPage" runat="server" CommandName="prev" OnCommand="Page_OnClick">上页</asp:LinkButton>
<asp:LinkButton ID="lbnNextPage" runat="server" CommandName="next" OnCommand="Page_OnClick">下页</asp:LinkButton>
<asp:LinkButton ID="lbnLastPage" runat="server" CommandName="last" OnCommand="Page_OnClick">未页</asp:LinkButton>
<asp:DropDownList ID="myDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="listchanged">
</asp:DropDownList>
</form>
</body>
</html>
- DataList分页代码
- Datalist分页代码
- datalist数字分页代码
- DataList分页代码
- DataList分页的完整代码
- DataList控件的分页代码
- 简单的datalist分页代码
- Asp.net DataList 分页代码
- VB.NET DATALIST 分页代码
- 简单的datalist分页代码
- asp.net datalist 分页显示代码
- asp.net DataList控件分页代码
- datalist分页
- DataList 分页
- datalist分页
- DataList分页
- datalist 分页
- DataList分页
- 在pop3服务器上找到新的邮件
- 探秘嫦娥一号背后的软件开发故事
- 使用DataList控件
- 图片上传
- 转:asp随机数字验证码 生成BMP图 不需要补丁
- Datalist分页代码
- 人海搜“脸”
- 常见控件用法.
- BeanFactory与Application的区别
- DataBinder.Eval总结
- Java EE 5的SOA考验(长春JAVA培训班 吉林长春JAVA软件就业培训)
- .NET Remoting——first things first(1):抛砖引玉
- 佛学中的108条做人道理
- 线程的暂停、恢复和终止