1
我有一個Telerik的報表項目添加到我的網站,我想傳遞參數給它,但我收到以下錯誤傳遞參數Telerik的報告
Error:
Object reference not set to an instance of an object.
Asp.net代碼
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MembershipCard rpt = new MembershipCard();
// Error occuring here
rpt.ReportParameters["@MemberID"].Value = "5"; // Request["MemberID"];
ReportViewer1.Report = rpt;
}
}
Telerik的報告類
public MembershipCard()
{
/// <summary>
/// Required for telerik Reporting designer support
/// </summary>
InitializeComponent();
this.DataSource = null;
}
private void MembershipCard_NeedDataSource(object sender, EventArgs e)
{
string proc = "rpt_MembershipCard" + this.ReportParameters["@MemberID"].Value.ToString();
SqlDataAdapter adapter = new SqlDataAdapter(proc, "Data Source=(local); Initial Catalog= northwind; intergrated security = True");
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
(sender as Telerik.Reporting.Processing.Report).DataSource = dataSet;
}
可有人請點我在正確的方向我一直沒能找到任何與互聯網相關的東西。
當我嘗試你的建議,我得到的錯誤「rpt_PrintMembershipCard」不包含「ReportParameters」的定義,並沒有擴展方法「ReportParameters」接受一個類型的第一個參數「 rpt_PrintMembershipCard「可以找到(您是否缺少使用指令或程序集引用?) – Noelle
@Wellie是您創建的報告的rpt_PrintMembershipCard名稱?你應該有rpt_PrintMembershipCard.cs文件。 您的班級定義應該是: '公共部分班級rpt_PrintMembershipCard:Telerik.Reporting.Report' –
.cs文件是MembershipCard.cs並且報告查看器所在的網頁是rpt_PrintMembershipCard – Noelle