// -------------------------
// ASP.NET (myReport.aspx):
<asp:ListBox ID="myListBox" AutoPostBack="true" OnSelectedIndexChanged="OnSelectMyListBox_Click"
AppendDataBoundItems="True" runat="server" DataSourceID="MyListBoxDataSource" DataTextField=" myListBoxItem"
DataValueField="id" SelectionMode="Multiple" Rows="9">
<asp:ListItem Selected="True" Value="">All ListBox Items</asp:ListItem>
</asp:ListBox>
// Code Behind (myReport.aspx.cs):
string URL;
URL = "viewReport.aspx?page=detail" + "&lbid" + myListBox.SelectedValue;
// -------------------------
// ASP.NET (viewMyReport.aspx):
<CR:CrystalReportViewer ID="myReport" runat="server" AutoDataBind="True"
Height="1055px" Width="920px" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False"
ReuseParameterValuesOnRefresh="True" />
// Code Behind (viewMyReport.aspx.cs) (loads Crystal Report):
private ReportDocument reportDocument = new ReportDocument();
protected void Page_Init(object sender, EventArgs e)
{
txtPageID.Text = Request.QueryString["page"];
myListboxID = Request.QueryString["lbid"];
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
//Set instances for input parameter 2 -
paramField = new ParameterField();
paramField.Name = "@myLbId";
paramDiscreteValue = new ParameterDiscreteValue();
if (myListBoxID == "")
{
paramDiscreteValue.Value = DBNull.Value;
}
else
{
paramDiscreteValue.Value = myListBoxID;
}
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);
MyReport.ParameterFieldInfo = paramFields;
reportDocument.Load(Server.MapPath("MyReport.rpt"));
reportDocument.SetDatabaseLogon("myUserName", "myPassword");
MyReport.ReportSource = reportDocument;
}
// -------------------------
// Crystal Report (MyReport.rpt)
// Calls SQL Stored Procedure and displays the data
// -------------------------
// SQL Stored Procedure (populates data on Crystal Report):
alter procedure [dbo].[GenerateMyReport]
@myLbId int
as
begin
select
*
from
myTable
where
myColumn = @myLbId
end
//-------------------------
|