asp.net Repeater 第二次绑定出现 “未将对象引用设置到对象的实例。”
public void BindrepStudentList(int num)
{
DataTable dt = StudentBll.GetInfoByNum(num);
this.repStudentList.DataSource = dt;
this.repStudentList.DataBind();
dt = null;
}
这里的参数num是下面sql 语句用到的start
public DataTable GetInfoByNum(int start)
{
if (start > 1)
return SqlDbHelper.ExecuteDataTable(@"select top 5 stuID,stuName,stuSex,IdentificationNumber,className,stuYear from tb_Student s inner join tb_Class c
on s.classID = c.classID where stuID>all(select top " + (start - 1) + " stuID from tb_Student order by stuID asc) ");
else
{
return SqlDbHelper.ExecuteDataTable(@"select top 5 stuID,stuName,stuSex,IdentificationNumber,className,stuYear from tb_Student s inner join tb_Class c
on s.classID = c.classID ");
}
}
第一次加载数据没问题,关键是第二次翻页的时候,我是使用jq用ajax跳转到一般处理程序加载数据的
private void DoLoadData()
{
string strStartNum = context.Request.Params["startNum"];
if (!PageHelper.IsNum(strStartNum))
{
AjaxMsgHelper.AjaxMsg("error", "Ajax传值,传向StudentManager.ashx页面的参数异常.");
}
else
{
Web.Manager.View.StudentManager StudentManager = new View.StudentManager();
StudentManager.BindrepStudentList(int.Parse(strStartNum));
}
}
就这样又调用最上面的方法 ,然后就出错了
<html>
<head>
<title>未将对象引用设置到对象的实例。</title>
<meta name="viewport" content="width=device-width" />
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
@media screen and (max-width: 639px) {
pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
}
@media screen and (max-width: 479px) {
pre { width: 280px; }
}
</style>
</head>
<body bgcolor="white">
<span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1>
<h2> <i>未将对象引用设置到对象的实例。</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
<br><br>
<b> 异常详细信息: </b>System.NullReferenceException: 未将对象引用设置到对象的实例。<br><br>
<b>源错误:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>
行 21: {
行 22: DataTable dt = StudentBll.GetInfoByNum(num);
<font color=red>行 23: this.repStudentList.DataSource = dt;
</font>行 24: this.repStudentList.DataBind();
行 25: dt = null;</pre></code>
</td>
</tr>
</table>
<br>
<b> 源文件: </b> e:\论文项目\SkillExamination\SkillExamination.Web\Manager\View\StudentManager.aspx.cs<b> 行: </b> 23
<br><br>
<b>堆栈跟踪:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>
[NullReferenceException: 未将对象引用设置到对象的实例。]
SkillExamination.Web.Manager.View.StudentManager.BindrepStudentList(Int32 num) in e:\论文项目\SkillExamination\SkillExamination.Web\Manager\View\StudentManager.aspx.cs:23
SkillExamination.Web.Manager.Action.StudentManager.DoLoadData() in e:\论文项目\SkillExamination\SkillExamination.Web\Manager\Action\StudentManager.ashx.cs:67
SkillExamination.Web.Manager.Action.StudentManager.SonLoad() in e:\论文项目\SkillExamination\SkillExamination.Web\Manager\Action\StudentManager.ashx.cs:21
SkillExamination.Web.Manager.Action.AdminBaseHandler.ProcessRequest(HttpContext context) in e:\论文项目\SkillExamination\SkillExamination.Web\Manager\Action\AdminBaseHandler.ashx.cs:23
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
</pre></code>
</td>
</tr>
</table>
<br>
<hr width=100% size=1 color=silver>
<b>版本信息:</b> Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.34212
</font>
</body>
</html>