Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am wanting to set the visibility of a ASP:LINKBUTTON based on the condition of the Repeaters DataSource property TYPE

if the DataItem.Type property == "practical" set visibility to true otherwise false;

Obviously some rows in the datasource will be true and some will be false, i only want to to hide the current row not all buttons.

I have tried the below code:

HTML
Visible="<%# DataBinder.Eval(Container,"DataItem.Type").ToString().ToLower() == "practical" ? true : false %>"


i have also tried the values true and false in speech marks but to no prevail:

error i recieve is:

Parser Error Message: The server tag is not well formed.

Source Error: 


Line 84:                                     </td>
Line 85:                                     <td width="17%">
Line 86: <asp:LinkButton runat="server" ID="lbAddDates" Visible="<%# DataBinder.Eval(Container,"DataItem.Type").ToString().ToLower() == "practical" ? "true" : "false" %>" CommandName="AddDates" OnCommand="lbCourseActionItems_Click" CommandArgument='<%# DataBinder.Eval(Container, "DataItem.Id").ToString() + "," + DataBinder.Eval(Container, "DataItem.IsActive").ToString() + "," + DataBinder.Eval(Container, "DataItem.Title").ToString()  %>' class="button">
</asp:LinkButton>


Any help on this would be greatly appreciated.
Posted
Updated 3-Sep-14 6:16am
v2

1 solution

Your server tag includes quotes. Use single quotes as outer quotes to get a wellformed tag.
C#
Visible='<%# DataBinder.Eval(Container,"DataItem.Type").ToString().ToLower() == "practical" ? true : false %>'
 
Share this answer
 
Comments
Grant Weatherston 4-Sep-14 4:07am    
could you explain why this should work? as i always thought you had to have "" when naming variables in html, e.g runat="server", ID = "button1" etc. Whats the difference between '' and ""
kbrandwijk 4-Sep-14 4:47am    
The SGML specification for HTML 4 states the following about attribute values: "By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa. Authors may also use numeric character references to represent double quotes (") and single quotes ('). For double quotes authors can also use the character entity reference ".

In certain cases, authors may specify the value of an attribute without any quotation marks. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation marks even when it is possible to eliminate them."

However, the XHTML specification is more strict, saying: "All attribute values must be quoted, even those which appear to be numeric."

So it doesn't really matter what you do. However, using double quotes for the attribute value when there are already double quotes inside the server tag, will always cause your tag to be NOT well formed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900