<%@ Page Inherits="Defaultpage" Src="Default.aspx.cs" %>
<html>
<head runat="server">
<title>新闻系统</title>
</head>
<body>
<center>asp.net新闻系统</center>
<table>
<asp:DataGrid ID="xinwen" runat="server" AllowCustomPaging="true" PagerStyle-NextPageText="下一页"
PagerStyle-PrevPageText="上一页"
PagerStyle-Visible="true" AllowPaging="true" PageSize="20" PagerStyle-Mode="NextPrev" OnPageIndexChanged="ChangePage" AutoGenerateColumns="false" EnableViewState="true">
<HeaderStyle BackColor="#00aaaa"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="D_ID" HeaderText="id"/>
<asp:BoundColumn DataField="D_Title" HeaderText="标题"/>
<asp:BoundColumn DataField="D_Writer" HeaderText="作者"/>
<asp:BoundColumn DataField="D_Date" HeaderText="发布时间"/>
</Columns>
</asp:DataGrid>
</table>
</body>
</html>
代码:Default.aspx.cs;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
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;
public partial class Defaultpage : System.Web.UI.Page
{
public DataGrid xinwen;
DataSet ds = new DataSet();
void xinwenBind() {
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=e:\work\nxy.mdb";
string strSQL = "SELECT D_ID, D_Title, D_Writer, D_Date FROM NewsData";
OleDbConnection objConnection = new OleDbConnection(strConnection);
OleDbDataAdapter da = new OleDbDataAdapter(strSQL,objConnection);
da.Fill(ds, "NewsData");
xinwen.DataSource = ds.Tables["NewsData"];
xinwen.DataBind();
}
public void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
xinwenBind();
}
}
public void ChangePage(Object sender,DataGridPageChangedEventArgs e){
xinwen.CurrentPageIndex = e.NewPageIndex;
xinwen.DataSource = ds.Tables["NewsData"];
xinwen.DataBind();
}
}
可是我的结果是
显示有上一页 下一页
但是没的链接!!!
不知道为什么??
[此贴子已经被作者于2007-9-20 15:17:48编辑过]