示例图:
根据数据判断,显示各种不同的图片
该列的前端代码:
<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属性。