After checking a condition I want to hide or view an image button inside a gridView
.
I tried to like this. but it is not working.
<asp:GridView ID="GridView1" runat="server" Width="100%" CssClass="grid" AutoGenerateColumns="False"
EnableModelValidation="True" DataKeyNames="T_ID" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowCommand="GridView1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="TEMPL_TITLE" HeaderText="Title">
<HeaderStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="TEMPL_DESC" HeaderText="Description">
<HeaderStyle Width="200px" />
</asp:BoundField>
<asp:BoundField HeaderText="Category" DataField="CAT_NAME" />
<asp:BoundField HeaderText="Workflow Type" DataField="WFTYPE_DESCRIPTION" />
<asp:BoundField HeaderText="Owner" DataField="EMP_CALLING_NAME" />
<%# if(Eval("EXP_PENDING_APPR").ToString() == "0") { %>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ViewImageButton1" runat="server" CommandArgument='<%# Eval("TEMPL_ID") %>'
ImageUrl="Images/jdAttView.gif" OnCommand="btnViewTemplate_Click" ToolTip="View and download template" />
</ItemTemplate>
</asp:TemplateField>
<% } %>
</Columns>
<EmptyDataTemplate>
No templates have been assigned to you security capabilites, Please contact your
local administrator for more information.
</EmptyDataTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:GridView>
The error with this code The error with this code
CodePudding user response:
You can apply condition on server control itself.
<asp:ImageButton Visible='<%# Eval("EXP_PENDING_APPR").ToString().Equals("0") %>' ID="ViewImageButton1" runat="server" CommandArgument='<%# Eval("TEMPL_ID") %>' ImageUrl="Images/jdAttView.gif" OnCommand="btnViewTemplate_Click" ToolTip="View and download template" />