Bind button visibility to the expresion (C#)

Posted by drasto on Stack Overflow See other posts from Stack Overflow or by drasto
Published on 2010-05-19T22:53:24Z Indexed on 2010/05/19 23:00 UTC
Read the original article Hit count: 308

Filed under:
|
|
|
|

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 ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET