Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
26 Feb 2010 1  
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:

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here