20150709---Web中GridView控件根据绑定的数据显示不同的图片

示例图:

image

根据数据判断,显示各种不同的图片

该列的前端代码:

<asp:TemplateField HeaderText="审图">
      <ItemTemplate>
              <asp:ImageButton ID="imgbtnTest" runat="server" ImageUrl ='<%# GetImgSrcTest(Eval("SpecialtyNum").ToString())%>' ></asp:ImageButton>
      </ItemTemplate>
      <ItemStyle Width="60px" />
</asp:TemplateField>

后台代码:

        protected string GetImgSrcTest(string SpecialtyNum)
        {
            if (SpecialtyNum != "")
            {
                int ex = int.Parse(SpecialtyNum);

                if (ex == 0)
                    return "../Images/Small/060.gif";
                else
                    return "../Images/Small/066.gif";
            }
            else
                return "../Images/Small/002.gif";
        }

跟据数据进行判断,返回不同的string字符串,作为ImageButton 的 ImageUrl属性。

posted @ 2015-07-09 11:57  Tirisfal  阅读(308)  评论(0编辑  收藏  举报