示例图:

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

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

该列的前端代码:

<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属性。

相关文章:

  • 2022-01-06
  • 2021-09-24
  • 2021-11-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-08-25
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案