Bind button visibility to the expresion (C#)
- by drasto
I have a delete button in each row of GridView (component ASP.NET). I want some of the delete buttons to be invisible. The visibility of the delete button should depend on the data that are back the row.
GridView is backed by EntityDataSource. GridView displays entities called Category, one instance in each row. Entity Category has (besides others) also a field of type EntityCollection. Name of that field is Items. Basically I want to allow user to delete a row only if the Items field of backing Category entity is an empty collection.
I cannot make up the binding of Visible property. I have no experience with bindings and Google does not really help.
This is how the button looks right now:
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete"
Visible=??? ></asp:Button>
I don't know what should replace ???. The button schold be visible only when this expression evaluates to true:
((SimpleEShop.Model.Category) dataItem).Items.LongCount() <= 0
where dataItem variable contains data of current row in the table.
What is the binding that I need ?