将参数从listview传递到crystal报表

时间:2015-10-22 02:49:14

标签: c# asp.net listview crystal-reports

我是为网络应用程序创建水晶报告的新手。我正在尝试将listview项中的参数传递给水晶报表

我正在使用它来传递参数

<a href='../Reports/UserDetails.aspx?ID=<%# Eval("UserID") %>'><i class= "fa fa-print"></i>

这是我用于调用水晶报告的aspx后面的代码

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();
}
}

enter image description here

我调试程序,它一直在询问我想要发送的参数。它不能再要求价值

1 个答案:

答案 0 :(得分:0)

取消注释参数行report.SetParameterValue("@UserID", ID); 如果不起作用,请从UserID参数中删除@符号,并在crystal report中设置相同的名称参数。