GridView图像字段从DB中获取空图像源

时间:2015-04-19 05:57:48

标签: asp.net ms-access gridview imagefield

在ASP应用程序中,我有一个查询,它从ms访问数据库中检索指向图像的链接。我在GridView中添加了一个字段,向我显示查询在boundfield中返回的内容,并得到以下输出:#http://www.xenonauts.com/images/RPG7_colour.png#

但是,图像字段(绑定到查询中的同一个字段)返回到包含断开链接的源 - 在页面源中,我看到<img src="">

为什么会这样?我怎么能解决这个问题?

代码隐藏在C#中 - 如果您需要更多代码(即数据库调用和查询),我很乐意提供它。

修改: gridView的ID是Items。

绑定代码:

public void UpdateSource()
    {
        Items.DataSource = (DataSet)Cache["Items"];
        Items.DataBind();
    }

public void fillShopGridForUser(string username)
    {
        Cache["Items"] = DbManager.getUserShopItemDS(username,getItemsForUser(username));
    }

// in the page load:
if (Cache["Items"] == null)
            {
                fillShopGridForUser(((User)Session["User"]).Username);
            }
            UpdateSource();
// in a different class - DbManager :
static public DataSet getUserShopItemDS(string username,List<shopItem> items)
    {
        string madeForCommand = "SELECT ItemName as Name,ItemPicture as Picture..." // It has more to it, but they are less relevant.
        OleDbCommand command = GenerateConnection(madeForCommand);
        //Add the relevant item IDs to the parameters- this works pretty OK, if you need it let me know.
        var FreestyleAdaptor = new OleDbDataAdapter();
        FreestyleAdaptor.SelectCommand = command;
        DataSet Items = new DataSet();
        FreestyleAdaptor.Fill(Items);
        return Items;
    }

0 个答案:

没有答案