首页 > 开发 > 综合 > 正文

web页面用水晶报表的例子

2024-07-21 02:16:38
字体:
来源:转载
供稿:网友
///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><br>
<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>
<br>
<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><br>
<font size="2">customer profile</b></font><br><br><br>
<font size="1"> <b>change pages</b></font><br>
<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"/>
<br><br>
<font size="1"> search for text<br></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;
        }
    }
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表