在asp gridview中加载gif

时间:2016-04-15 10:54:32

标签: c# asp.net gridview

我有一个asp:GridView,它从数据库中检索一些数据。基于其中一列。如果列中的项具有特定值(例如“processing”),则加载gif应出现在下一列中。如果值是“成功”那么没有gif出现,它应该只是空格?

任何想法都会感激不尽。

由于

1 个答案:

答案 0 :(得分:0)

Usually I place a TemplateField when I have some little more than simple data show. I place on GridView that two fields

<asp:BoundField DataField="cStatus" ... />

<asp:TemplateField SortExpression="cStatus" ... >
    <ItemTemplate ><%#GetStatusIcon(Container.DataItem)%></ItemTemplate>
</asp:TemplateField>

and on code behind the function that return the image that I like to show as:

protected string GetStatusIcon(object oItem)
{
    // a sample how to get your value. Change the type to yours one (eg string)
    bool fStatus = (bool)DataBinder.Eval(oItem, "cStatus");

    if (fStatus)
        return "<img src=\"one.gif\" />";
    else
        return "<img src=\"other.gif\" />";
}