Reputation: 11498
In a GridView, I'm trying to show either one column or an other using a public Boolean property:
<Columns>
...
<asp:BoundField Visible="<%= !ShowPurchaseDate %>" DataField="Published" HeaderText="Publicerad" SortExpression="PriceRange" DataFormatString="{0:yyyy.MM.dd}" HtmlEncode="false" />
<asp:BoundField Visible="<%= ShowPurchaseDate %>" DataField="OrderDate" HeaderText="Köpt" SortExpression="OrderDate" DataFormatString="{0:yyyy.MM.dd}" HtmlEncode="false" />
...
</Columns>
But I'm getting an error message saying that it's not possible to create a System.Boolean from a string that contains <% !ShowPurchaseDate %> for property Visisble.
How can I achive this?
UPDATE:
<%# !ShowPurchaseDate %> doesn't work either as there's no databinding going on.
Using a protected funktion doesn't work either (same error message as with property).
Upvotes: 1
Views: 3005
Reputation:
you could try calling a method instead of binding like shouldshowcolumn().
Upvotes: 1
Reputation: 11498
I solved it through:
gridMain.Columns[ShowPurchaseDate ? 3 : 4].Visible = false;
Is this the best solution?
Upvotes: 2
Reputation: 1013
Provide a protected method in the code behind that returns the boolean property as a string.
Upvotes: 0