直播中
編寫客戶端網(wǎng)頁(yè)文件index.aspx
<%@page language="C#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="Wmj.ViewDB"%>
<html>
<head>
<title>我的留言板</title>
</head>
<body>
<form runat="server">
<center>
<asp:DataGrid id="dataGrid1" ItemStyle-BackColor="#AAAADD" AutoGenerateColumns="false"
AlternatingItemStyle-BackColor="#CCCCFF" HeaderStyle-BackColor="#000000"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-ForeColor="#FFFFFF" PagerStyle-Mode="NumericPages"
AllowPaging="true" PageSize="4" Font-Size="10pt" runat="server">
<columns>
<asp:BoundColumn HeaderText="序號(hào)" DataField="ID"/>
<asp:BoundColumn HeaderText="標(biāo)題" DataField="Title"/>
<asp:BoundColumn HeaderText="留言人" DataField="NoterName"/>
<asp:BoundColumn HeaderText="留言時(shí)間" DataField="NoteTime" DataFormatString="{0:dd/MM/yyyy}"/>
</columns>
</asp:DataGrid>
<asp:Label id="label1" runat="server"/>
</center>
</form>
</body>
</html>
編寫客戶端文件的codebehind index.aspx.cs
////////////////////////////////////////////////////////////////////
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using DBService; //引入客戶端文件的名字空間
namespace Wmj
{
public class ViewDB : Page
{
protected DataGrid dataGrid1;
public ViewDB()
{
this.Init+=new EventHandler(this.Page_Init);
}
public void Page_Init(object sender,EventArgs e)
{
this.Load+=new EventHandler(this.Page_Load);
this.dataGrid1.PageIndexChanged+=new
DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
}
public void Page_Load(object sender,EventArgs e)
{
ViewDBService viewDBService=new ViewDBService();
//使用webservice
dataGrid1.DataSource=viewDBService.ViewDB().Tables["NoteBoard"].DefaultView;
if(!Page.IsPostBack)
{
dataGrid1.CurrentPageIndex=0;
dataGrid1.DataBind();
}
}
public void DataGrid1_PageIndexChanged(object sender,DataGridPageChangedEventArgs e)
{
dataGrid1.CurrentPageIndex=e.NewPageIndex;
dataGrid1.DataBind();
}
}