This is a migrated thread and some comments may be shown as answers.

[Solved] Condiotional formatting with ItemTemplate

1 Answer 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jasper
Top achievements
Rank 1
Jasper asked on 22 May 2009, 03:51 PM
Hi,

I want to format an ItemTemplate conditionally but can't find a way to get archieve this.

I've read the Conditional Formatting for rows/cells on ItemDataBound topic but can't apply it to an ItemTemplate.

For example my aspx code:

                    <ItemTemplate> 
                        <span style="display: block; float: left;"
                            <%# Eval (Session["ntyp"].ToString())%> 
                        </span>
                        <
span style="display: block; float: right;"
                            <%# Eval("date")%> 
                        </span> 
                        <br /> 
                        <span> 
                            <%# Eval("subject")%> 
                        </span> 
                    </ItemTemplate> 

All what I want to do is, give the "subject" an individul style, depending on the value of "read" which is stored in the same table (not visible to users here) and could be empty or a string.

If I use a simple if statement checking the value using Eval("read") inside the ItemTemplate it trhows a TargetInvocationException.

Any help would be appreciated.

Regards

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 26 May 2009, 11:48 AM
Hello Jasper,

You may consider using declarative conditional binding expression to determine the value from the source field with name 'read' and apply your custom css class for the span which holds the subject value. Review the solution from this KB article for more details on the approach and verify that your SELECT query includes the 'read' field.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Jasper
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or