vc2005,access
前台代码
<!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>
<title>无标题页</title>
</head>
<div>
<asp:repeater id="LeaveMessage" runat="server" >
<ItemTemplate>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#D4D0C8">
<tr>
<td width="85%" bgcolor="#FFFAFF"><div align="left"><%#DataBinder.Eval(Container.DataItem, "News_Title")%></div></td>
<td width="15%" bgcolor="#FFFAFF" align="left"><%#DataBinder.Eval(Container.DataItem, "News_Time")%></td>
</tr>
</table>
<hr size="3px" width="90%"/>
</ItemTemplate>
</asp:repeater>
</div>
<body>共有<asp:Literal ID="RecordCount" runat="server"></asp:Literal>条记录
共有<asp:Literal ID="PageCount" runat="server"></asp:Literal>页
当前第<asp:Literal ID="Pageindex" runat="server"></asp:Literal>页
<asp:HyperLink ID="FirstPage" runat="server" Text="首页"></asp:HyperLink>
<asp:HyperLink ID="PrevPage" runat="server" Text="上一页"></asp:HyperLink>
<asp:HyperLink ID="NextPage" runat="server" Text="下一页"></asp:HyperLink>
<asp:HyperLink ID="LastPaeg" runat="server" Text="尾页"></asp:HyperLink>
<%--跳转到<asp:Literal ID="Literal1" runat="server"></asp:Literal>页--%></body></html>
后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;public partial class solid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//if (!Page.IsPostBack)
//{
NewsBind();
Console.WriteLine("我的名字是{0}"); //}
}
private void NewsBind()//repeater分页并绑定
{
string SqlStr = "select News_Title,News_Time from News order by News_Time";
string connectionString = System.Configuration.ConfigurationManager.AppSettings["shoolConnectionString"].ToString();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
conn.Open();
System.Data.SqlClient.SqlDataAdapter Adapter = new System.Data.SqlClient.SqlDataAdapter(SqlStr, conn);
DataSet ds = new DataSet();
try
{
Adapter.Fill(ds, "News");
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource=ds.Tables["News"].DefaultView;
objPage.AllowPaging=true;
objPage.PageSize=3;
int CurPage;
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
CurPage = 1;
objPage.CurrentPageIndex = CurPage - 1;
LeaveMessage.DataSource=objPage;//这里更改控件名称
LeaveMessage.DataBind();//这里更改控件名称
RecordCount.Text = objPage.DataSourceCount.ToString();
PageCount.Text = objPage.PageCount.ToString();
Pageindex.Text = CurPage.ToString();
Literal1.Text = PageList(objPage.PageCount, CurPage);
//Literal1.Text = PageList(objPage.PageCount, Pageindex, L_Manage); //带参数的:LManage为参数
FirstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1";
PrevPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (CurPage - 1);
NextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (CurPage + 1);
LastPaeg.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + objPage.PageCount.ToString();
if (CurPage <= 1 && objPage.PageCount <= 1)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
NextPage.NavigateUrl = "";
LastPaeg.NavigateUrl = "";
/**//**//**//*
68 FirstPage.Visible = false;
69 PrevPage.Visible = false;
70 NextPage.Visible = false;
71 LastPaeg.Visible = false;
72 */
}
if (CurPage <= 1 && objPage.PageCount > 1)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
/**//**//**//*
FirstPage.Visible = false;
PrevPage.Visible = false;
*/
}
if (CurPage >= objPage.PageCount)
{
NextPage.NavigateUrl = "";
LastPaeg.NavigateUrl = "";
/**//**//**//*
NextPage.Visible = false;
LastPaeg.Visible = false;
*/
}
}
}
catch(Exception error)
{
Response.Write(error.ToString());
}
finally
{
conn.Close();
}
}
//private string PageList(int Pagecount, int Pageindex)//private string Jump_List(int Pagecount , int Pageindex , long L_Manage)//带参数的传递
//{
// StringBuilder sb = new StringBuilder();
// //下为带参数的传递
// //sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '&Org_ID=" + L_Manage + "';\">");
// //不带参数的传递
// sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '';\">");
// for (int i = 1; i <= Pagecount; i++)
// {
// if (Pageindex == i)
// sb.Append("<option value='" + i + "' selected>" + i + "</option>");
// else
// sb.Append("<option value='" + i + "'>" + i + "</option>");
// }
// sb.Append("</select>");
// return sb.ToString();
//}
}
数据库有3个字段,News_Id,News_Title,News_Time.
这个程序怎么不值行
请高手指教一下,谢谢
前台代码
<!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>
<title>无标题页</title>
</head>
<div>
<asp:repeater id="LeaveMessage" runat="server" >
<ItemTemplate>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#D4D0C8">
<tr>
<td width="85%" bgcolor="#FFFAFF"><div align="left"><%#DataBinder.Eval(Container.DataItem, "News_Title")%></div></td>
<td width="15%" bgcolor="#FFFAFF" align="left"><%#DataBinder.Eval(Container.DataItem, "News_Time")%></td>
</tr>
</table>
<hr size="3px" width="90%"/>
</ItemTemplate>
</asp:repeater>
</div>
<body>共有<asp:Literal ID="RecordCount" runat="server"></asp:Literal>条记录
共有<asp:Literal ID="PageCount" runat="server"></asp:Literal>页
当前第<asp:Literal ID="Pageindex" runat="server"></asp:Literal>页
<asp:HyperLink ID="FirstPage" runat="server" Text="首页"></asp:HyperLink>
<asp:HyperLink ID="PrevPage" runat="server" Text="上一页"></asp:HyperLink>
<asp:HyperLink ID="NextPage" runat="server" Text="下一页"></asp:HyperLink>
<asp:HyperLink ID="LastPaeg" runat="server" Text="尾页"></asp:HyperLink>
<%--跳转到<asp:Literal ID="Literal1" runat="server"></asp:Literal>页--%></body></html>
后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;public partial class solid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//if (!Page.IsPostBack)
//{
NewsBind();
Console.WriteLine("我的名字是{0}"); //}
}
private void NewsBind()//repeater分页并绑定
{
string SqlStr = "select News_Title,News_Time from News order by News_Time";
string connectionString = System.Configuration.ConfigurationManager.AppSettings["shoolConnectionString"].ToString();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
conn.Open();
System.Data.SqlClient.SqlDataAdapter Adapter = new System.Data.SqlClient.SqlDataAdapter(SqlStr, conn);
DataSet ds = new DataSet();
try
{
Adapter.Fill(ds, "News");
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource=ds.Tables["News"].DefaultView;
objPage.AllowPaging=true;
objPage.PageSize=3;
int CurPage;
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
CurPage = 1;
objPage.CurrentPageIndex = CurPage - 1;
LeaveMessage.DataSource=objPage;//这里更改控件名称
LeaveMessage.DataBind();//这里更改控件名称
RecordCount.Text = objPage.DataSourceCount.ToString();
PageCount.Text = objPage.PageCount.ToString();
Pageindex.Text = CurPage.ToString();
Literal1.Text = PageList(objPage.PageCount, CurPage);
//Literal1.Text = PageList(objPage.PageCount, Pageindex, L_Manage); //带参数的:LManage为参数
FirstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1";
PrevPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (CurPage - 1);
NextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (CurPage + 1);
LastPaeg.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + objPage.PageCount.ToString();
if (CurPage <= 1 && objPage.PageCount <= 1)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
NextPage.NavigateUrl = "";
LastPaeg.NavigateUrl = "";
/**//**//**//*
68 FirstPage.Visible = false;
69 PrevPage.Visible = false;
70 NextPage.Visible = false;
71 LastPaeg.Visible = false;
72 */
}
if (CurPage <= 1 && objPage.PageCount > 1)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
/**//**//**//*
FirstPage.Visible = false;
PrevPage.Visible = false;
*/
}
if (CurPage >= objPage.PageCount)
{
NextPage.NavigateUrl = "";
LastPaeg.NavigateUrl = "";
/**//**//**//*
NextPage.Visible = false;
LastPaeg.Visible = false;
*/
}
}
}
catch(Exception error)
{
Response.Write(error.ToString());
}
finally
{
conn.Close();
}
}
//private string PageList(int Pagecount, int Pageindex)//private string Jump_List(int Pagecount , int Pageindex , long L_Manage)//带参数的传递
//{
// StringBuilder sb = new StringBuilder();
// //下为带参数的传递
// //sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '&Org_ID=" + L_Manage + "';\">");
// //不带参数的传递
// sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '';\">");
// for (int i = 1; i <= Pagecount; i++)
// {
// if (Pageindex == i)
// sb.Append("<option value='" + i + "' selected>" + i + "</option>");
// else
// sb.Append("<option value='" + i + "'>" + i + "</option>");
// }
// sb.Append("</select>");
// return sb.ToString();
//}
}
数据库有3个字段,News_Id,News_Title,News_Time.
这个程序怎么不值行
请高手指教一下,谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货