An easiest way to create a parameterized crystal report ? RRS feed

  • Question

  • User245461779 posted

    Hello !

    I have create a following parameterized crystal report using StoredProcedure on Northwind database.

    Is there any better and simplest way to create this report ?

    The report should provide print , export and refresh button facility.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <style type="text/css">
                width: 151px;
                width: 320px;
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <table border="1" bgcolor="#FFFFCC">
                    <td class="style1">
                        Select Category :
                    <td class="style2">
                        <asp:DropDownList ID="drpCategory" runat="server" Height="26px" Width="299px" 
                            DataSourceID="SqlDataSource1" DataTextField="CategoryName" 
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                            SelectCommand="SELECT * FROM [Categories]"></asp:SqlDataSource>
                    <td class="style1">
                        Select Order Year :
                    <td class="style2">
                        <asp:DropDownList ID="drpOrdYear" runat="server" Height="26px" Width="299px">
                            <asp:ListItem Selected="True">1996</asp:ListItem>
                    <td class="style1">
                    <td class="style2">
                        <asp:Button ID="btnShowRep" runat="server" Text="Show Report" Height="31px" />
            <br />
            <hr />
            <br />
            <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
                AutoDataBind="True" HasRefreshButton="True" ToolPanelView="None" 
                Visible="False" EnableDatabaseLogonPrompt="False" 
                EnableParameterPrompt="False" GroupTreeImagesFolderUrl="" Height="1202px" 
                onload="CrystalReportViewer1_Load" ToolbarImagesFolderUrl="" 
                ToolPanelWidth="200px" Width="903px" />

    --------- cs code ----------------

     void BindRep()
                DataTable dt = new DataTable();
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
                SqlCommand cmd = new SqlCommand("SalesByCategory", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@CategoryName", drpCategory.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@OrdYear", drpOrdYear.SelectedItem.Text);
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                ReportDocument rdoc = new ReportDocument();
                rdoc.SetDatabaseLogon("sa", "1", "mayurpc\\sqlexpress", "Northwind");
                rdoc.SetParameterValue("@CategoryName", drpCategory.SelectedItem.Text);
                rdoc.SetParameterValue("@OrdYear", drpOrdYear.SelectedValue);
                CrystalReportViewer1.ReportSource = rdoc;
                CrystalReportViewer1.Visible = true;
            protected void CrystalReportViewer1_Load(object sender, EventArgs e)
                if (IsPostBack)
    Saturday, December 31, 2011 11:08 AM


  • User-231977777 posted

    Is there any better and simplest way to create this report ?

    it is up to you ,

    reading data from database each time you need , Or storing Data into DataTable and use Rowfilter Property with DataView to filter data , all is ok. and your way is Ok.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 31, 2011 8:17 PM