Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to apply condition in repeater control.

If the field in database table in null or empty, the label associated with it must not be displayed.

Have tried with this:

XML
<asp:Label ID="Label1" runat="server" Font-Size="X-Large" ForeColor="DeepSkyBlue"
                   Style="position: static" Text="Search Results" visible="<%# CanIDisplayBeds(DataBinder.Eval(Container.DataItem,"Beds")) %>" ></asp:Label>


where code behind has following function:
C#
protected bool CanIDisplayBeds(Object retBeds)
    {
        return (retBeds != "");
    }


Getting error: "Server tag not well formed."

Please help.

I cant make out what to do.

Now I have found out the solution.
It is as below...
Posted
Updated 5-Aug-11 4:41am
v3
Comments
Dalek Dave 17-Apr-11 7:46am    
Edited for grammar and readability.

Hi....
I have got the Solution!!!!!

For this, I have removed the function from code behind, removed the label and just added following code in aspx page.
Its as follows.

<%#(DataBinder.Eval(Container.DataItem,"Beds").ToString()=="")?" ": " Bedroom "%>


Am happy now!!!!!
 
Share this answer
 
Comments
thatraja 23-Mar-11 2:58am    
Glad... you have solved yourself. 5! for you own answer posted here.
Tech Code Freak 25-Mar-11 2:52am    
Hey Thanks!!
Dalek Dave 17-Apr-11 7:47am    
Always good to solve it yourself!
Ankur\m/ 29-Apr-11 5:10am    
Was checking out your answers, why 2 same answers here. Delete the other one.
Tale a look at this[^] article to know how to handle Handling Empty Data in an ASP.NET Repeater control
 
Share this answer
 

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