如何解決此異常?未將對象引用設置爲對象的實例(NullreferenceException未由用戶代碼處理)
Dim imagepathlit As Literal = DownloadsRepeater.FindControl("imagepathlit")
imagepathlit.Text = imagepath
這裏是轉發器:
<asp:Repeater ID="DownloadsRepeater" runat="server">
<HeaderTemplate>
<table width="70%">
<tr>
<td colspan="3"><h2>Files you can download</h2></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="5%">
<asp:Literal ID="imagepathlit" runat="server"></asp:Literal></td>
<td width="5%"></td>
<td> </td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
這裏是獲取數據的中繼器的代碼:
c.Open()
r = x.ExecuteReader
While r.Read()
If r("filename") Is DBNull.Value Then
imagepath = String.Empty
Else
imagepath = "<img src=images/" & getimage(r("filename")) & " border=0 align=absmiddle>"
End If
End While
c.Close()
r.Close()
更多的解釋是必要的,添加相關的代碼 – Brij 2010-04-14 12:18:01
你可以粘貼中繼ASPX一部分?確保imagepathlit不存在於您要查找的位置。如果你粘貼aspx,我們可以用適當的方法來回答 – 2010-04-14 12:22:53