Click here to Skip to main content
16,016,263 members
Articles / Web Development / ASP.NET

Programmatically Pass Parameters into Crystal Reports from ASP.NET (C#) - Part 2

Rate me:
Please Sign up or sign in to vote.
2.14/5 (4 votes)
25 Feb 2010CPOL 29.1K   4   10
How to programmatically pass parameters into Crystal Reports from ASP.NET, using C# - Part 2.

Introduction

This is the second part of my article: Programmatically Pass Parameters into Crystal Reports from ASP.NET (C#) - Part 1.

Using the code

We use the filters variable which is declared as a ParamType class:

C#
public class FilterType
{
  public const string DateTime = "DateTime";
  public const string MultiSelect = "MultiSelect";
  public const string String = "String";
  public FilterType()
  { 
  }
}

public class ParamType
{
  private TextBox[] datetimeFilters = new TextBox[100];
  private xMilk.DropCheck[] multiselectFilters = new xMilk.DropCheck[100];
  private TextBox[] stringFilters = new TextBox[100];
  public string[] filterType = new string[100];
  private int index = -1;
  public ParamType()
  { 
  }
  public void AddDateTimeFilter(TextBox myTextBox)
  {
    index += 1;
    filterType[index] = FilterType.DateTime;
    datetimeFilters[index] = myTextBox;
  }
  public void AddMultiSelectFilter(xMilk.DropCheck myDropCheck)
  {
    index += 1;
    filterType[index] = FilterType.MultiSelect;
    multiselectFilters[index] = myDropCheck;
  }
  public void AddStringFilter(TextBox myTextBox)
  {
    index += 1;
    filterType[index] = FilterType.String;
    stringFilters[index] = myTextBox;
  }
  public string GetParamTextByIndex(int i)
  {
    string returnText = "";
    switch (filterType[i])
    {
      case FilterType.DateTime:
        returnText = datetimeFilters[i].Text;
        break;
      case FilterType.MultiSelect:
        returnText = multiselectFilters[i].Text;
        break;
      case FilterType.String:
        returnText = stringFilters[i].Text;
        break;
    }
    return returnText;
  }
  public string GetParamTypeByIndex(int i)
  {
    return filterType[i];
  }
}

Snapshots

launch.jpg

filters.jpg

In this sample, when the user clicks on report1 which uses four parameters (two DateTime, and two multiselect type), the ReportView.aspx page will be dynamically created. The datetime picker has a simple client-side JavaScript which was added as an attribute in the AddDateTimeFilter() method. The multiselect filters use a special DropCheck webcontrol which is not a standard built-in webcontrol, but can be downloaded as a DLL.

Summary

There is a known small bug in this sample and I'm hoping to get an answer here. The bug: when you click on report1, everything goes fine, but after that, if you click on report2, the ReportView.aspx page does not refresh. The second report has only three parameters, but the first report's parameters are coming in again, and this is really annoying.

I hope you found this article useful, and if you have any questions, please let me know.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Website Administrator
Hungary Hungary
Working with Microsoft Dynamics NAV since 2007.

Comments and Discussions

 
GeneralPublishing OK, but JScript doesn't appear to run Pin
Bob Clegg17-May-10 16:18
Bob Clegg17-May-10 16:18 
GeneralRe: Publishing OK, but JScript doesn't appear to run Pin
Mihaly Sogorka17-May-10 21:26
Mihaly Sogorka17-May-10 21:26 
GeneralRe: Publishing OK, but JScript doesn't appear to run [modified] Pin
Mihaly Sogorka17-May-10 21:54
Mihaly Sogorka17-May-10 21:54 
GeneralPublishing Woes Pin
Bob Clegg16-May-10 18:57
Bob Clegg16-May-10 18:57 
GeneralRe: Publishing Woes Pin
Mihaly Sogorka16-May-10 21:42
Mihaly Sogorka16-May-10 21:42 
GeneralDTP closer Pin
Bob Clegg16-May-10 15:55
Bob Clegg16-May-10 15:55 
GeneralRe: DTP closer Pin
Mihaly Sogorka16-May-10 21:47
Mihaly Sogorka16-May-10 21:47 
Generalcalendarsetup Application setting Pin
Bob Clegg13-May-10 15:02
Bob Clegg13-May-10 15:02 
GeneralRe: calendarsetup Application setting [modified] Pin
Mihaly Sogorka13-May-10 22:02
Mihaly Sogorka13-May-10 22:02 
Hi Bob!
Yes it is Zapatec Datetimepicker a client side javascript.
If you provide me with your e-mail address I can send you the
source code of this small calendar because it was very hard to
find on internet.
BUT here is the code for using it:

In your .aspx page put this code in the header section:
<head runat="server">
    <title>Client Side Calendar Sample</title>

    <link rel="stylesheet" href="javascripts/datetimepicker/themes/forest.css" />
    <link rel="stylesheet" href="javascripts/datetimepicker/themes/layouts/small.css" />
    <script type="text/javascript" src="javascripts/datetimepicker/src/calendar.js"></script>
    <script type="text/javascript" src="javascripts/datetimepicker/lang/calendar-en.js"></script>

</head>


And also put a textbox control on your page (it must be between the form tags):
<body>
    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </form>
</body>


Now your codebehind code should look like this:
protected void Page_Load(object sender, EventArgs e)
{
  string calendarSetup = "Zapatec.Calendar.setup({firstDay: 1,weekNumbers: true,showOthers: true,electric: false,inputField: '" + 
  TextBox1.ClientID + "',button:'" + 
  TextBox1.ClientID + "',ifFormat:'%Y-%m-%d',daFormat: '%Y-%m-%d'});";

  TextBox1.Attributes.Add("onclick", calendarSetup);
}


This way you can assign the textbox onclick event with Zapatec calendar picker but
you must put the javascript in a subdirectory inside your application root like this:
\%application_root%\javascripts\datetimepicker\

Best regards,
Mihaly Sogorka

modified on Tuesday, May 18, 2010 4:12 AM

GeneralMy vote of 1 Pin
Dave Kreskowiak26-Feb-10 1:24
mveDave Kreskowiak26-Feb-10 1:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.