Answer: we can call code behind function in the gridview as follows
In asp.net markup:
<asp:TemplateField HeaderText="IsEnable">
<ItemTemplate>
<center>
<asp:Image ID="imgUserState" runat="server" Width="10px" Height="10px" ImageUrl='<%#GetImage(Eval("IsEnable")) %>'></asp:Image>
</center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IsApprover">
<ItemTemplate>
<center>
<asp:Image ID="imgApproverState" runat="server" Width="10px" Height="10px" ImageUrl='<%#GetImage(Eval("IsApprover")) %>'></asp:Image>
</center>
</ItemTemplate>
</asp:TemplateField>
In c# code behind file
protected string GetImage(object ob)
{
bool IsActive = Convert.ToBoolean(ob);
if (IsActive) return @"~/images/yes.png";
else return @"~/images/no.png";
}
Output is:
No comments:
Post a Comment