示例图:

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

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

该列的前端代码:

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

04-19 16:17
查看更多