如何在后台定义<td>里面的字段
代码:
<td style= "height: 286px; width: 394px; ">
<table width= "500 " border= "0 " cellspacing= "0 " cellpadding= "0 ">
<tr align= "center ">
<td class= "p3 " > <br/> <%=dr[ "Title "]%> </td>
</tr>
<tr align= "center ">
<td style= "height: 49px "> <div> <hr size= "1 " style= "height: 28px; width: 190px; " id= "HR1 " onclick= "return HR1_onclick() " />
<font color= "#999999 " "> [ <%=dr[ "Time "]%> ] </font> <br/>
</div>
</td>
</tr>
<tr>
<td style= "height: 33px ">
<%
if(dr[ "Image "] != " ") {
Response.Write( " <Image src=‘ " + dr[ "Image "] + "‘ border=0 align=‘left‘ width=‘20‘ height=‘200‘> ");
}
%> <br/> <%=dr[ "Content "]%>
</td>
</tr>
<tr>
<td> <br />
<br/> 摘自: <%=dr[ "ComeTo "]%>
<br/>
</td>
</tr>
<tr>
<td style= "height: 18px ">
<div align= "right "> </div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height= "17 " style= "width: 394px ">
<table width= "498 " border= "0 " cellspacing= "0 " cellpadding= "0 " "mmto.gif " style= "height: 27px ">
<tr>
<td width= "172 " style= "background:mmto.gif; height: 18px; "> 本条消息被浏览了
<font color= "#FF3333 "> [ <%=dr[ "Counter "]%> ] </font> 回
</td>
报错:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 68: <table width= "500 " border= "0 " cellspacing= "0 " cellpadding= "0 ">
行 69: <tr align= "center ">
行 70: <td class= "p3 " > <br/> <%=dr[ "Title "]%> </td>
行 71: </tr>
行 72: <tr align= "center ">
那么怎么定义呢?
谢谢!
[解决办法]
楼主 要先确定dr 是不是为空 然后dr 要定义成public
建议采用:
<%#dr[ "title "]%> 这种绑定形式;
在后台判断:
if(dr.Read())
{
Page.DataBind();
}