web页面用水晶报表的例子

80酷酷网    80kuku.com

  web|水晶报表|页面///customnav.aspx
<% Register TagPrefix="CrystalReports" Namespace="SeagateSoftware.Web" Assembly="SeagateSoftware.Web" %>
<% Page Src="CustomNav.cs" Inherits="CRSamples.CustomNav" %>

<html>

<body>

<form method="post" runat="server">
<center>
<font face="Verdana" size=4>Custom Navigation</font>

<table border="0" width="90%">
<tr><td>
<p align="justify"><font face="Verdana" size="1">
The default navigation method for the Crystal Reports Web Form Viewer Control is the Toolbar
panel. However, web developers can create their own navigation interface for the report. In
the example below, the Toolbar is hidden, and the user navigates the report by clicking image
button controls in the navigation bar along the left side of the page. This provides for a very
customizable interface to suit any web site. This also demonstrates how the Web Form Viewer
can respond to events fired by other Web Controls easily.
</font>
</td></tr>
</table>


<table border="0" width="90%">
<tr>
<td valign="top" bgcolor="#bfa57d" width="230">
<font face="Arial" size="3" color="white"><b><i>Xtreme Mountain Bikes</i>

<font size="2">Customer Profile</b></font>



<font size="1"> <b>Change Pages</b></font>

<asp:ImageButton id="btnFirstPage" runat="server" imageUrl="images/first_page.gif" ToolTip="First Page"/> 
<asp:ImageButton id="btnPrevPage" runat="server" imageUrl="images/prev_page.gif" ToolTip="Previous Page"/> 
<asp:ImageButton id="btnNextPage" runat="server" imageUrl="images/next_page.gif" ToolTip="Next Page"/> 
<asp:ImageButton id="btnLastPage" runat="server" imageUrl="images/last_page.gif" ToolTip="Last Page"/>



<font size="1"> Search for Text
</font>
<asp:TextBox id="txtSearch" runat="server" width="100"/>
<asp:Button id="btnSearch" runat="server" height="22" Text="Search"/>
</font>
</td>
<td valign="top" align="middle">
<CrystalReports:CrystalReportViewer id="CrystalReportViewer1" runat="server" width="350px" height="50px" pagetotreeratio="4"
displaytoolbar="false" displaygrouptree="false"/>
</td>
</tr>
</table>
</center>
</form>

</body>

</html>

///customnav.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Win32;
using SeagateSoftware.Web;
using System.Web.UI.WebControls;

namespace CRSamples
{    
    public class CustomNav : System.Web.UI.Page
    {
        protected CrystalReportViewer CrystalReportViewer1;
        protected ImageButton btnFirstPage;
        protected ImageButton btnPrevPage;
        protected ImageButton btnNextPage;
        protected ImageButton btnLastPage;
        protected TextBox txtSearch;
        protected Button btnSearch;

        protected void Page_Init(object sender, EventArgs e)
        {            
            btnFirstPage.Click += new ImageClickEventHandler(this.btnFirstPage_Click);
            btnPrevPage.Click += new ImageClickEventHandler(this.btnPrevPage_Click);
            btnNextPage.Click += new ImageClickEventHandler(this.btnNextPage_Click);
            btnLastPage.Click += new ImageClickEventHandler(this.btnLastPage_Click);
            btnSearch.Click += new EventHandler(this.btnSearch_Click);

            CrystalReportViewer1.ReportName = GetSampleReportsDir() + "Feature Examples\\Sort Multiple Field.rpt";
        }

        protected void btnPrevPage_Click(object source, ImageClickEventArgs e)
        {            
            PageNavigateEventArgs pageNavEvtArgs = new PageNavigateEventArgs();
            pageNavEvtArgs.NewPageNumber = CrystalReportViewer1.PageRequestContext.PageNumber - 1;
            CrystalReportViewer1.OnPageNavigate(source, pageNavEvtArgs);
        }

        protected void btnNextPage_Click(object source, ImageClickEventArgs e)
        {
            PageNavigateEventArgs pageNavEvtArgs = new PageNavigateEventArgs();
            pageNavEvtArgs.NewPageNumber = CrystalReportViewer1.PageRequestContext.PageNumber + 1;
            CrystalReportViewer1.OnPageNavigate(source, pageNavEvtArgs);
        }

        protected void btnFirstPage_Click(object source, ImageClickEventArgs e)
        {
            PageNavigateEventArgs pageNavEvtArgs = new PageNavigateEventArgs();
            pageNavEvtArgs.NewPageNumber = 1;
            CrystalReportViewer1.OnPageNavigate(source, pageNavEvtArgs);
        }

        protected void btnLastPage_Click(object source, ImageClickEventArgs e)
        {
            PageNavigateEventArgs pageNavEvtArgs = new PageNavigateEventArgs();
            pageNavEvtArgs.NewPageNumber = CrystalReportViewer1.PageViewer.LastPageNumber;
            CrystalReportViewer1.OnPageNavigate(source, pageNavEvtArgs);
        }

        protected void btnSearch_Click(object source, EventArgs e)
        {
            SearchEventArgs searchEvtArgs = new SearchEventArgs();
            searchEvtArgs.TextToSearch = txtSearch.Text;
            searchEvtArgs.PageNumberToBeginSearch = CrystalReportViewer1.PageRequestContext.PageNumber;
            CrystalReportViewer1.OnSearch(source, searchEvtArgs);
        }

        private String GetSampleReportsDir()
        {
            // Get the path VS was installed to
            RegistryKey regKey = Registry.LocalMachine;    
            regKey = regKey.OpenSubKey("Software\\Microsoft\\VisualStudio\\7.0\\Setup\\VS");
            string dir = regKey.GetValue("ProductDir").ToString();
            dir += "Crystal Reports\\Samples\\Reports\\";
            return dir;
        }
    }
}

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: