I am new at creating a crystal report for web application. I'm trying to pass a parameter from a listview item to a crystal report
I'm using this to pass the parameter
<a href='../Reports/UserDetails.aspx?ID=<%# Eval("UserID") %>'><i class= "fa fa-print"></i>
This is the code I use for behind the aspx that calls the crystal report
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["ID"] != null)
{
if (Request.QueryString["ID"] != null)
{
int userID = 0;
bool validUser = int.TryParse(Request.QueryString["ID"].ToString(), out userID);
if (validUser)
{
if (!IsPostBack)
{
GetInfo(userID);
}
}
else
Response.Redirect("Default.aspx");
}
else
Response.Redirect("Default.aspx");
}
}
void GetInfo(int ID)
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Users.UserID, Types.UserType, Users.Email, Users.LastName, " +
"Users.FirstName, Users.ContactNumber, Branch.BranchName, Users.Status, Users.DateAdded, " +
"Users.DateModified FROM Users " +
"INNER JOIN Types ON Users.TypeID = Types.TypeID " +
"INNER JOIN Branch ON Users.BranchID = Branch.BranchID WHERE UserID=@UserID";
cmd.Parameters.AddWithValue("@UserID", Request.QueryString["ID"].ToString());
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Users");
ReportDocument report = new ReportDocument();
report.Load(Server.MapPath("~/Admin/Reports/rptUserDetails.rpt"));
//report.SetParameterValue("@UserID", ID);
//report.SetParameterValue("@UserID", ID);
crvUsers.ReportSource = report;
crvUsers.DataBind();
con.Close();
}
}
I debug the program it keeps on asking the parameter I am trying to send. It must not anymore ask for the value
uncomment the parameter line report.SetParameterValue("@UserID", ID);
if it not work remove the @ symbol from UserID parameter and also set the same name parameter in crystal report.