主页  |  Opensoft Websites  |  OSDN  |  下载中心
工具栏

HTML 代码
<asp:ToolBar ID="ToolBar1" runat="server"></asp:ToolBar>
Javascript 代码

C# 代码
protected void Page_PreRender(object sender, EventArgs e) {
    ToolBarDescription description = new ToolBarDescription(base.GetString("DataDesign"));
    this.ToolBar1.ToolItems.Add(description);
    ToolBarButton previousPageButton = new ToolBarButton();
    previousPageButton.ImageUrl = "App_Images/Icons/PreviousPage.gif";
    previousPageButton.ToolTip = base.GetString("ToolBar.PreviousPage");
    previousPageButton.OnClientClick = base.GetScript("OnChangePageIndex", "previous");
    previousPageButton.OnClientRefresh = base.GetScript("OnQueryPageState", "previous");
    this.ToolBar1.ToolItems.Add(previousPageButton);
    ToolBarButton nextPageButton = new ToolBarButton();
    nextPageButton.ImageUrl = "App_Images/Icons/NextPage.gif";
    nextPageButton.ToolTip = base.GetString("ToolBar.NextPage");
    nextPageButton.OnClientClick = base.GetScript("OnChangePageIndex", "next");
    nextPageButton.OnClientRefresh = base.GetScript("OnQueryPageState", "next");
    this.ToolBar1.ToolItems.Add(nextPageButton);
    ToolBarDropDownList changePageDropDownList = new ToolBarDropDownList();
    changePageDropDownList.Items.Add(new ToolBarListItem(base.GetString("PageFormatText", "1"), "0"));
    changePageDropDownList.OnClientSelectedIndexChanged = base.GetScript("OnChangePageIndex", "change");
    changePageDropDownList.OnClientRefresh = base.GetScript("OnQueryPageState", "change");
    this.ToolBar1.ToolItems.Add(changePageDropDownList);
    ToolBarButton deleteButton = new ToolBarButton();
    deleteButton.ImageUrl = "App_Images/Icons/Delete.gif";
    deleteButton.ToolTip = base.GetString("ToolBar.Delete");
    deleteButton.OnClientClick = base.GetScript("OnChangePageIndex", "delete");
    deleteButton.OnClientRefresh = base.GetScript("OnQueryPageState", "delete");
    this.ToolBar1.ToolItems.Add(deleteButton);
    string pageFormatText = base.GetScriptLine("PageFormatText", base.GetString("PageFormatText"));
    base.ClientScript.RegisterClientScriptBlock(base.GetType(), "PageFormatText", pageFormatText, true);
    base.ClientScript.RegisterClientScriptBlock(base.GetType(), "ChangePageIndex", base.GetScriptLine("ChangePageIndex"), true);
}


// Javascript
var __pageCount = 1;
var __pageIndex = 0;
function __changePageIndex(sender, type) {
    if (type == "previous") {
        if (__pageIndex == 0) {
            return;
        }
        __pageIndex--;
    } else if (type == "next") {
        if (__pageIndex == 19) {
            return;
        }
        if (__pageIndex == __pageCount - 1) {
            __pageCount++;
        }
        __pageIndex++;
    } else if (type == "delete") {
        if (__pageCount > 1) {
            __pageCount--;
        }
        if (__pageIndex > __pageCount - 1) {
            __pageIndex--;
        }
    } else {
        var element = document.getElementById(sender.id);
        __pageIndex = element.selectedIndex;
    }
}
function __queryPageState(sender, type) {
    if (type == "previous") {
        if (__pageIndex == 0) {
            sender.setState(1);
        } else {
            sender.setState(2);
        }
    } else if (type == "next") {
        if (__pageIndex == 19) {
            sender.setState(1);
        } else {
            sender.setState(2);
        }
    } else if (type == "delete") {
        if (__pageCount == 1) {
            sender.setState(1);
        } else {
            sender.setState(2);
        }
    } else {
        var element = document.getElementById(sender.id);;
        var length = element.options.length;
        for (var num = length; num > __pageCount; num--) {
            element.remove(num - 1);
        }
        for (var num = length; num < __pageCount; num++) {
            element.options[num] = new Option(String.format(__pageFormatText, [num + 1]), num);
        }
        element.selectedIndex = __pageIndex;
    }
}
Copyright © 2005 - 2008 Opensoft Corporation. All rights reserved.