Expression Bind Button Visibility (C #)

I have a delete button on each line GridView

(ASP.NET component). I want some of the delete buttons to be invisible. The visibility of the delete button should depend on the data that is returned in the row.

GridView

supported EntityDataSource

. GridView

displays named objects, Category

one instance on each line. The object Category

has (among others) also a type field EntityCollection

. The name of this field Items

. Basically, I want to allow the user to delete a row only if the Items

lookup field Category

is an empty collection.

I am unable to compose a property binding Visible

. I have no experience with bindings and google doesn't really help. This is what the button looks like right now:

<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                    Text="Delete" 
                    Visible=??? ></asp:Button>

      

I don't know what should be replaced ???

. The schold button is visible only when this expression evaluates to true:

((SimpleEShop.Model.Category) dataItem).Items.LongCount() <= 0

      

where the variable dataItem

contains the data of the current row in the table. What binding do I need?

+2


a source to share


3 answers


egrunin missed some things, try this like this



Visible='<%# !(((System.Data.Objects.DataClasses.EntityCollection<YourItemType>)Eval("Items")).Count <= 0 )%>'

      

+3


a source


I used to put this in a DataBound handler, but how about something like this:

Visible="<%# Eval("Items.LongCount") <= 0 ? "false" : "true";%>"

      



Quotes inside quotes can cause errors, which is one of the reasons I would put it in the ItemDataBound handler.

+3


a source


Adding to the egrunin syntax, I would simply use

Visible='<%# Eval("Items.Count") <= 0 %>'

      

+2


a source







All Articles