crystal-reportsC#(cSharp) Crystal Reports 

How to pass multiple values to single SetParameterValue() in C# Crystal Reports

Passing multiple values to single SetParameterValue() in C# Crystal Reports

We faced this problem in Crystal Reports while filtering data based on multiple values for a single parameter in c#
example: if you are using listitems and you are selecting multiple values to be passed to crystal report for filtering then you can use like this as below code snippet.

First, add using system collections

using System.Collections;

then create one arraylist object and read listitem and add to arrayList as below (this below code is for listitems)

ArrayList arrayList = new ArrayList();
        foreach (ListItem item in CheckBoxList.Items)
        {
 
            if (item.Selected)
            {
                arrayList.Add(item.Value.ToString());
            }
        }

and (This below is code is for GroupSelectionList items)

ArrayList arrayList = new ArrayList();
for (int i = 0; i < groupSelectionList.Items.Count; i++){
	if (groupSelectionList.GetItemCheckState(i) == CheckState.Checked)
	{
		arrayList.Add(((ListItem)groupSelectionList.Items[i]).Value.ToString());
	}
}

Then, at last, add ArrayList to SetParameterValue by typecasting it to an array (ToArray())

 cryRpt.SetParameterValue("Pname", arrayList.ToArray());

 

Also Read:  How to remove extension .aspx/.html in asp/c# web application

Related posts