他の画像が存在しない場合にデフォルトの画像を表示できるように、コード ビハインドで asp Image タグにアクセスしようとしています。私が抱えている問題は、「オブジェクト参照がオブジェクトのインスタンスに設定されていません」というメッセージが表示されることです。エラーメッセージ。aspx ページ
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MemberProfileList.ascx.cs"
Inherits="UserControls_MemberProfileList" %>
<%--<asp:GridView ID="GridView1" runat="server">
</asp:GridView>--%>
<asp:DataList ID="profilelist" runat="server" RepeatColumns="2" OnDataBinding="profilelist_DataBound" >
<ItemTemplate>
<asp:Image ID="ProfileImage" runat="server" ImageUrl='<%# System.String.Format("/Images/{0}", DataBinder.Eval(Container.DataItem, "ProfilePictureThumb"))%>' />
<asp:Hyperlink runat="server" NavigateUrl='<%#Link.ToSpecificMemberProfile(Eval("Username").ToString()) %>' Text='<%#HttpUtility.HtmlDecode(Eval("Username").ToString()) %>' />
</ItemTemplate>
</asp:DataList>
コードビハインドのメソッド
profilelist.DataSource = myProfileList;
profilelist.DataBind();
Image ProfileImage = profilelist.FindControl("ProfileImage") as Image;
string profilepic = ProfileImage.ImageUrl.ToString();
if (profilepic == null)
{
ProfileImage.Visible = false;
}
どんな助けでも大歓迎です