Saturday, 15 May 2010

c# - "if" Conditions in Formview Markup -



c# - "if" Conditions in Formview Markup -

i want show pupil study card using form view. study card have additional columns, if study card 2nd term , 2 more columns, if 3rd term. find out term is, need evaluate termnumber property, , show appropriate heading. mark code:

<% if ((int)eval("termnumber") == 2) %> <% { %> <th> 1st term score</th> <% } %> <% else if ((int)eval("termnumber") == 3) %> <% { %> <th> 1st term score</th> <th> 2nd term score</th> <% } %>

this results in run time error : databinding methods such eval(), xpath(), , bind() can used in context of databound control.

this because eval can part of <%# %> tag.

using <%# %> results in compile time error, , vs13 intellisense, says invalid term.

my question is: how can succeed in achieving target of conditionally showing columns. can utilize if status in markup of databound controls? or there other way accomplish this, without creating separate formviews each term.

the form view, has repeater command show subject scores, , needs utilise if condition.

so answering own question. hint ruben's accepted reply at: eval in if statement?

<th runat="server" visible='<%# (int)eval("termnumber") > 1 %>'>1st term score</th> <th runat="server" visible='<%# (int)eval("termnumber") > 2 %>'>2nd term score</th>

this works without problems in repeater control. visible property runat="server" doesn't includes markup, in final output, works fine. , code more elegant if blocks.

c# asp.net entity-framework webforms formview

No comments:

Post a Comment