Associate TemplateField Visibility with BoundField Content

The expression (pseudo-code) inside the "visible" tag of the TemplateField is what I like, any ideas? I really would like to do this declaratively. No OnRowCreated event handling, cells [x], ...

<asp:GridView ID="GridViewTest" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundField DataField="MyProperty" HeaderText="My Property" /> <asp:TemplateField Visible="<%# MyProperty == 'VisibleString' %>"> <ItemTemplate> <asp:ImageButton ID="ImageButton1" runat="server" AlternateText="" ImageUrl="" OnClick="ImageButton1_Click" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> 
+4
source share
1 answer

This could not be done in the TemplateField column because it does not have DataBinding support. I had to do this in ImageButton. Now it works fine:

 <asp:ImageButton Visible='<%# Eval("MyProperty") == "VisibleString" %>' [...] /> 
+3
source

Source: https://habr.com/ru/post/1433951/


All Articles