系列 五--讲述page的分页
可以看看实现的效果图
CheckBox:Show Page Info------show or hide Page total information
DropDownList:Place-----show page navigation top , bottom or topbottom
ChekBox:Image Navigation---determine whether use arrow image or not
DropDownList:Page Type----determine use whick page navigation :NextPrev,NextPrevWithQuickGo,Numeric, NumericWithQuickGo, QuickGo
DropDownList:Goto Page Type:---quick go type:edit or dropdownlist(hide)
aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="demo002.aspx.cs" Inherits="itwms.page.demo002" %>
<%@ Register Assembly="WebDataWindow" Namespace="Sybase.DataWindow.Web" TagPrefix="dw" %>
<!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>DataWindow.Net Page Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="typeLabel" runat="server" Text="Page Type:" Width="77px" style="z-index: 100; left: 8px; overflow: auto; position: absolute; top: 76px;"></asp:Label>
<asp:Label ID="gotoPageTypeLabel" runat="server" Style="z-index: 100; left: 8px; overflow: auto;
position: absolute; top: 100px" Text="GoTo Page Type:" Width="122px" Visible="False"></asp:Label>
<asp:Label ID="placeLabel" runat="server" Style="z-index: 100; left: 8px; overflow: auto;
position: absolute; top: 29px" Text="Place:" Width="83px"></asp:Label>
<div style="width: 860px; height: 323px; z-index: 100; left: 14px; overflow: auto; position: absolute; top: 130px;">
<dw:WebDataWindowControl ID="webDWcntrl" runat="server" DataWindowObject="dw_cust_grid" Height="291px" LibraryList="~/page/northwind.pbl" Width="824px" AutoRestoreDataCache="True" AutoSaveDataCacheAfterRetrieve="True" PagingMethod="Callback" RowsPerPage="10" Visible="False">
<PageNavigationBarSettings Visible="True">
<BarStyle Font-Names="Verdana" Font-Size="Medium" />
</PageNavigationBarSettings>
</dw:WebDataWindowControl>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Generate" style="z-index: 100; left: 787px; overflow: auto; position: absolute; top: 15px;" />
<asp:CheckBox ID="imageCheckBox" runat="server" style="z-index: 100; left: 99px; overflow: auto; position: absolute; top: 53px;" Text="Image Navigation" Width="174px" />
<asp:CheckBox ID="pageInfoCheckBox" runat="server" style="z-index: 100; left: 99px; overflow: auto; position: absolute; top: 5px;" Text="Show Page Info" Width="176px" />
<asp:DropDownList ID="placeDropDownList" runat="server" style="z-index: 100; left: 99px; overflow: auto; position: absolute; top: 28px;" Width="176px" >
<asp:ListItem>Top</asp:ListItem>
<asp:ListItem>Bottom</asp:ListItem>
<asp:ListItem>TopBottom</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="typeDropDownList" runat="server" style="z-index: 100; left: 99px; overflow: auto; position: absolute; top: 76px;" Width="176px" OnSelectedIndexChanged="typeDropDownList_SelectedIndexChanged" AutoPostBack="True" >
<asp:ListItem Selected="True">NextPrev</asp:ListItem>
<asp:ListItem>NextPrevWithQuickGo</asp:ListItem>
<asp:ListItem>Numeric</asp:ListItem>
<asp:ListItem>NumericWithQuickGo</asp:ListItem>
<asp:ListItem>QuickGo</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="gotoPageTypeDropDownList" runat="server" style="z-index: 100; left: 134px; overflow: auto; position: absolute; top: 100px;" Width="176px" OnSelectedIndexChanged="typeDropDownList_SelectedIndexChanged" AutoPostBack="True" Visible="False" >
<asp:ListItem>Edit</asp:ListItem>
<asp:ListItem>DropDowList</asp:ListItem>
</asp:DropDownList></div>
</form>
</body>
</html>
<head runat="server">
<title>DataWindow.Net Page Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="typeLabel" runat="server" Text="Page Type:" Width="77px" style="z-index: 100; left: 8px; overflow: auto; position: absolute; top: 76px;"></asp:Label>
<asp:Label ID="gotoPageTypeLabel" runat="server" Style="z-index: 100; left: 8px; overflow: auto;
position: absolute; top: 100px" Text="GoTo Page Type:" Width="122px" Visible="False"></asp:Label>
<asp:Label ID="placeLabel" runat="server" Style="z-index: 100; left: 8px; overflow: auto;
position: absolute; top: 29px" Text="Place:" Width="83px"></asp:Label>
<div style="width: 860px; height: 323px; z-index: 100; left: 14px; overflow: auto; position: absolute; top: 130px;">
<dw:WebDataWindowControl ID="webDWcntrl" runat="server" DataWindowObject="dw_cust_grid" Height="291px" LibraryList="~/page/northwind.pbl" Width="824px" AutoRestoreDataCache="True" AutoSaveDataCacheAfterRetrieve="True" PagingMethod="Callback" RowsPerPage="10" Visible="False">
<PageNavigationBarSettings Visible="True">
<BarStyle Font-Names="Verdana" Font-Size="Medium" />
</PageNavigationBarSettings>
</dw:WebDataWindowControl>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Generate" style="z-index: 100; left: 787px; overflow: auto; position: absolute; top: 15px;" />
<asp:CheckBox ID="imageCheckBox" runat="server" style="z-index: 100; left: 99px; overflow: auto; position: absolute; top: 53px;" Text="Image Navigation" Width="174px" />
<asp:CheckBox ID="pageInfoCheckBox" runat="server" style="z-index: 100; left: 99px; overflow: auto; position: absolute; top: 5px;" Text="Show Page Info" Width="176px" />
<asp:DropDownList ID="placeDropDownList" runat="server" style="z-index: 100; left: 99px; overflow: auto; position: absolute; top: 28px;" Width="176px" >
<asp:ListItem>Top</asp:ListItem>
<asp:ListItem>Bottom</asp:ListItem>
<asp:ListItem>TopBottom</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="typeDropDownList" runat="server" style="z-index: 100; left: 99px; overflow: auto; position: absolute; top: 76px;" Width="176px" OnSelectedIndexChanged="typeDropDownList_SelectedIndexChanged" AutoPostBack="True" >
<asp:ListItem Selected="True">NextPrev</asp:ListItem>
<asp:ListItem>NextPrevWithQuickGo</asp:ListItem>
<asp:ListItem>Numeric</asp:ListItem>
<asp:ListItem>NumericWithQuickGo</asp:ListItem>
<asp:ListItem>QuickGo</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="gotoPageTypeDropDownList" runat="server" style="z-index: 100; left: 134px; overflow: auto; position: absolute; top: 100px;" Width="176px" OnSelectedIndexChanged="typeDropDownList_SelectedIndexChanged" AutoPostBack="True" Visible="False" >
<asp:ListItem>Edit</asp:ListItem>
<asp:ListItem>DropDowList</asp:ListItem>
</asp:DropDownList></div>
</form>
</body>
</html>
cs code:
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;
namespace itwms.page
{
public partial class demo002 : System.Web.UI.Page
{
private Sybase.DataWindow.Transaction Trans;
private System.ComponentModel.IContainer container;
protected void Page_Load(object sender, EventArgs e)
{
InitializeComponent();
//if (!IsPostBack)
//{
// Trans.Connect();
// webDWcntrl.SetTransaction(Trans);
// webDWcntrl.Retrieve();
//}
}
{
public partial class demo002 : System.Web.UI.Page
{
private Sybase.DataWindow.Transaction Trans;
private System.ComponentModel.IContainer container;
protected void Page_Load(object sender, EventArgs e)
{
InitializeComponent();
//if (!IsPostBack)
//{
// Trans.Connect();
// webDWcntrl.SetTransaction(Trans);
// webDWcntrl.Retrieve();
//}
}
private void InitializeComponent()
{
container = new System.ComponentModel.Container();
Trans = new Sybase.DataWindow.Transaction(container);
Trans.Dbms = Sybase.DataWindow.DbmsType.OleDb;
Trans.Password = "password";
Trans.UserId = "sa";
Trans.AutoCommit = false;
Trans.Lock = "RC";
Trans.DbParameter = "PROVIDER='SQLOLEDB',DATASOURCE='server',PROVIDERSTRING='database=Northwind'";
}
{
container = new System.ComponentModel.Container();
Trans = new Sybase.DataWindow.Transaction(container);
Trans.Dbms = Sybase.DataWindow.DbmsType.OleDb;
Trans.Password = "password";
Trans.UserId = "sa";
Trans.AutoCommit = false;
Trans.Lock = "RC";
Trans.DbParameter = "PROVIDER='SQLOLEDB',DATASOURCE='server',PROVIDERSTRING='database=Northwind'";
}
protected void Button1_Click(object sender, EventArgs e)
{
webDWcntrl.Visible = true;
Trans.Connect();
webDWcntrl.SetTransaction(Trans);
webDWcntrl.Retrieve();
setProperties();
}
private void setProperties()
{
if (pageInfoCheckBox.Checked)
{
webDWcntrl.PageNavigationBarSettings.PageStatusInfo.Visible = true;
webDWcntrl.PageNavigationBarSettings.PageStatusInfo.Position = Sybase.DataWindow.Web.PageStatusInfoPosition.Right;
}
else
{
webDWcntrl.PageNavigationBarSettings.PageStatusInfo.Visible = false;
}
{
webDWcntrl.Visible = true;
Trans.Connect();
webDWcntrl.SetTransaction(Trans);
webDWcntrl.Retrieve();
setProperties();
}
private void setProperties()
{
if (pageInfoCheckBox.Checked)
{
webDWcntrl.PageNavigationBarSettings.PageStatusInfo.Visible = true;
webDWcntrl.PageNavigationBarSettings.PageStatusInfo.Position = Sybase.DataWindow.Web.PageStatusInfoPosition.Right;
}
else
{
webDWcntrl.PageNavigationBarSettings.PageStatusInfo.Visible = false;
}
switch (placeDropDownList.SelectedIndex)
{
case 0:
webDWcntrl.PageNavigationBarSettings.Position = Sybase.DataWindow.Web.NavigationBarPosition.Top;
break;
case 1:
webDWcntrl.PageNavigationBarSettings.Position = Sybase.DataWindow.Web.NavigationBarPosition.Bottom;
break;
case 2:
webDWcntrl.PageNavigationBarSettings.Position = Sybase.DataWindow.Web.NavigationBarPosition.TopAndBottom;
break;
default:
goto case 1;
}
if (imageCheckBox.Checked)
{
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.FirstPageImageUrl = Page.Server.MapPath("../image/PageFirst.gif");
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.PrevPageImageUrl = Page.Server.MapPath("../image/PagePrior.gif");
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.NextPageImageUrl = Page.Server.MapPath("../image/PageNext.gif");
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.LastPageImageUrl = Page.Server.MapPath("../image/PageLast.gif");
}
else
{
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.FirstPageImageUrl = "";
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.PrevPageImageUrl = "";
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.NextPageImageUrl = "";
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.LastPageImageUrl = "";
}
switch (typeDropDownList.SelectedIndex)
{
case 0:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.NextPrev;
break;
case 1:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.NextPrevWithQuickGo;
break;
case 2:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.Numeric;
break;
case 3:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.NumericWithQuickGo;
break;
case 4:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.QuickGo;
break;
default:
goto case 0;
}
if (typeDropDownList.SelectedIndex.Equals(4))
{
switch (gotoPageTypeDropDownList.SelectedIndex)
{
case 0:
webDWcntrl.PageNavigationBarSettings.QuickGoNavigator.Type = Sybase.DataWindow.Web.QuickGoPageNavigatorType.Edit;
break;
case 1:
webDWcntrl.PageNavigationBarSettings.QuickGoNavigator.Type = Sybase.DataWindow.Web.QuickGoPageNavigatorType.DropDownList;
break;
}
}
}
{
case 0:
webDWcntrl.PageNavigationBarSettings.Position = Sybase.DataWindow.Web.NavigationBarPosition.Top;
break;
case 1:
webDWcntrl.PageNavigationBarSettings.Position = Sybase.DataWindow.Web.NavigationBarPosition.Bottom;
break;
case 2:
webDWcntrl.PageNavigationBarSettings.Position = Sybase.DataWindow.Web.NavigationBarPosition.TopAndBottom;
break;
default:
goto case 1;
}
if (imageCheckBox.Checked)
{
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.FirstPageImageUrl = Page.Server.MapPath("../image/PageFirst.gif");
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.PrevPageImageUrl = Page.Server.MapPath("../image/PagePrior.gif");
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.NextPageImageUrl = Page.Server.MapPath("../image/PageNext.gif");
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.LastPageImageUrl = Page.Server.MapPath("../image/PageLast.gif");
}
else
{
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.FirstPageImageUrl = "";
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.PrevPageImageUrl = "";
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.NextPageImageUrl = "";
webDWcntrl.PageNavigationBarSettings.NextPrevNavigator.LastPageImageUrl = "";
}
switch (typeDropDownList.SelectedIndex)
{
case 0:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.NextPrev;
break;
case 1:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.NextPrevWithQuickGo;
break;
case 2:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.Numeric;
break;
case 3:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.NumericWithQuickGo;
break;
case 4:
webDWcntrl.PageNavigationBarSettings.NavigatorType = Sybase.DataWindow.Web.PageNavigatorType.QuickGo;
break;
default:
goto case 0;
}
if (typeDropDownList.SelectedIndex.Equals(4))
{
switch (gotoPageTypeDropDownList.SelectedIndex)
{
case 0:
webDWcntrl.PageNavigationBarSettings.QuickGoNavigator.Type = Sybase.DataWindow.Web.QuickGoPageNavigatorType.Edit;
break;
case 1:
webDWcntrl.PageNavigationBarSettings.QuickGoNavigator.Type = Sybase.DataWindow.Web.QuickGoPageNavigatorType.DropDownList;
break;
}
}
}
protected void typeDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
imageCheckBox.Visible = true;
switch (typeDropDownList.SelectedIndex)
{
case 2:
goto case 3;
case 4:
gotoPageTypeDropDownList.Visible = true;
gotoPageTypeLabel.Visible = true;
goto case 3;
case 3:
imageCheckBox.Checked = false;
imageCheckBox.Visible = false;
break;
}
}
}
}
{
imageCheckBox.Visible = true;
switch (typeDropDownList.SelectedIndex)
{
case 2:
goto case 3;
case 4:
gotoPageTypeDropDownList.Visible = true;
gotoPageTypeLabel.Visible = true;
goto case 3;
case 3:
imageCheckBox.Checked = false;
imageCheckBox.Visible = false;
break;
}
}
}
}
当然这些,是通过code实现的,因为我为了页面实现多种分页方式,下面介绍一下,属性设置某一种分页方式:
如图:
我们可以随意设置,几个需要强调的地方:
a,RowsPerPage不能为0;
b,各自对应的visible不要忘记;