[英]Object reference not set to an instance of an object. - c# - Repeater - DataSet
Hi there, the above image shows the exception i'm getting everytime I filter the DataTable generated from the object I created. 嗨,上图显示了每次我过滤从创建的对象生成的DataTable时遇到的异常。
dtHistory = cBLRead.ds2.Tables["ScheduleHistory"]; dtHistory = cBLRead.ds2.Tables [“ ScheduleHistory”]; --> This actually populates the dtHistory. ->这实际上填充了dtHistory。
dtHistory.DefaultView.RowFilter = string.Format("[ExamScheduleID] in({0})", hdnID) --> This line filters the rows based on the hdnID... dtHistory.DefaultView.RowFilter = string.Format(“ [[ExamScheduleID] in({0})”,hdnID) ->此行基于hdnID过滤行...
rptHistory is already created in my ASP client side and it will remain empty not until the user clicks a specific row located in another DataTable... rptHistory已在我的ASP客户端中创建,并且直到用户单击位于另一个DataTable中的特定行之前,它将保持为空。
I pinned the dtHistory.Rows.Count to show that dtHistory is not null 我固定了dtHistory.Rows.Count以显示dtHistory不为null
How will I solve this one? 我将如何解决这个问题?
---Here's what I want to happen--- ---这就是我想发生的事情----
Everytime the user clicks a specific row of Examination from DataTable, a modal which contains a Repeater that shows the Reschedule History of Examination will pop-up. 每次用户单击DataTable中的特定考试行时,都会弹出一个模式,其中包含一个显示“重新安排考试历史记录”的Repeater。
The modal works ok but the repeater I have made does not. 模态工作正常,但我制作的中继器却不能。 What is probably the main cause of this exception.. 造成此异常的主要原因可能是什么。
Any reply will be appreciated. 任何答复将不胜感激。 Thanks! 谢谢!
The exception does not mean that dtHistory
is null
but that rptHistory
is null
. 该异常并不意味着dtHistory
为null
而是rptHistory
为null
。 Then as you are trying to dereference it to access the DataSource
property it throws. 然后,当您尝试取消引用它以访问它引发的DataSource
属性时。
In the screenshot the ScheduleHistory
method seems suspicious: 在屏幕快照中, ScheduleHistory
方法似乎可疑:
ClaretExamSchedule callMethod = new ClaretExamSchedule();
callMethod.FilterHistory(hdnId);
You instantiate a new object and call the FilterHistory
method which throws the exception because presumably the rptHistory
member is still unitialized. 您实例化一个新对象,然后调用FilterHistory
方法,该方法将引发异常,因为rptHistory
成员可能仍是统一的。
您应该像这样分配数据源
rptHistory.DataSource=dtHistory.Tables[0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.