Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在gridview中显示默认img_Asp.net_Gridview - Fatal编程技术网

Asp.net 在gridview中显示默认img

Asp.net 在gridview中显示默认img,asp.net,gridview,Asp.net,Gridview,我将在gridview中列出我的所有用户,我将为那些没有个人资料图片的用户显示一个默认图像 我已经看过这个解决方案,但我无法让它工作,我做错了什么 我的代码Gridview控件 代码隐藏OnRowDataBound: 您可以在图像控件本身中使用三值运算符来检查是否有图像,如果没有,则显示默认图像 <asp:Image ID="img" runat="server" ImageUrl='<%# !string.IsNullOrEmpty(Eval("fldImg").ToString

我将在gridview中列出我的所有用户,我将为那些没有个人资料图片的用户显示一个默认图像

我已经看过这个解决方案,但我无法让它工作,我做错了什么

我的代码Gridview控件

代码隐藏OnRowDataBound:


您可以在图像控件本身中使用三值运算符来检查是否有图像,如果没有,则显示默认图像

<asp:Image ID="img" runat="server" ImageUrl='<%# !string.IsNullOrEmpty(Eval("fldImg").ToString()) ? "../img/profil/" + Eval("fldImg") : "../img/profil/default-billede/ingen-profil-billede.png" %>' />

  protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {


        foreach (GridViewRow gvr in gwListeOverBruger.Rows)
        {
            Image image = (Image)gvr.FindControl("img");

            if (image != null && image.ImageUrl == "")
            {
                image.ImageUrl = "../img/profil/default-billede/ingen-profil-billede.png";
            }




        }
    }
}
 protected void gwListeOverBruger_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Image profilImg = (Image)e.Row.FindControl("img");

        if (profilImg != null && profilImg.ImageUrl == "")
        {
            profilImg.ImageUrl = "../img/profil/default-billede/ingen-profil-billede.png";
        }
    }
}
<asp:Image ID="img" runat="server" ImageUrl='<%# !string.IsNullOrEmpty(Eval("fldImg").ToString()) ? "../img/profil/" + Eval("fldImg") : "../img/profil/default-billede/ingen-profil-billede.png" %>' />