在一个DataGridView改变图像按钮栏图像 [英] Changing image in image button column in a datagridview

查看:138
本文介绍了在一个DataGridView改变图像按钮栏图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否有人曾经设法找到一种方法,有
在模板字段datagridview的图像按钮列其中显示根据不同行不同的图像
对行中的一些数据元素。我们的应用程序需要显示一系列
500到1000或> 1000冲减帐户列费用,这将是要么小于500。是一些这些费用以全速率充电,别人在部分速度,有些是不带电的。用户
想看到一个简单的三态图形这将传达出简单
信息:满充电,部分电荷或无电荷。听起来很简单,但足够
我没有能够找到一个方法来做到这一点。每次我试图
修改单个细胞的图形似乎要改变图形
对于所有的行

Just wondering if anyone has ever managed to find a way to have a datagridview image button column in a template field which display different images on different rows depending on some data element in the row. Our application needs to display a series of fees charged against an account column which will be either less then 500, 500 to 1000 or >1000. Some of those fees are charged at a full rate, others at a partial rate, and some are not charged at all. The user would like to see a simple 3-state graphic which would convey the simple info: full-charge, partial-charge, or no-charge. Sounds easy enough but I've not yet managed to find a way to do this. Every time I attempt to modify the individual cell's graphic it seems to want to change the graphic for all the rows.

解决此问题的任何方式?

Any way around this issue?

谢谢,

推荐答案

您可以用

<TemplateField>
    <ItemTemplate>
        <asp:ImageButton runat="server" ImageUrl='<%# GetImage(Eval("check") as string) %>' />
    </ItemTemplate>
</TemplateField>

其中,的getImage()是在code-背后的方法:

Where GetImage() is a method in your code-behind:

protected string GetImage(string check)
{
    if ((check == "2") || (check == "null") || (check == "3") || (check == "-1"))
    {
        return "../Interbacs/images/error.gif";
    }
    else if (check == "1") 
    {
        return "../Interbacs/images/ok.png"
    }

    return "what?";
}

这或许可以做一个小的prettier但我希望你的想法。

This can probably be done a little "prettier" but I hope you get the idea.

这篇关于在一个DataGridView改变图像按钮栏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆