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

[Solved] column.Template Conditional?

2 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
HaBo
Top achievements
Rank 1
HaBo asked on 14 Oct 2011, 04:23 AM
.Columns(columns =>
       {
           columns.Bound(e => e.PrescriptionID).Hidden();
           columns.Bound(e => e.RxType).Width(80).Title("Rx Type");
           columns.Bound(e => e.Medication);
           columns.Bound(e => e.SIG);
           columns.Bound(e => e.StartDate).Format("{0:d}").Width(100).Title("Start");
           columns.Bound(e => e.EndDate).Format("{0:d}").Width(100).Title("End");
            
           columns.Template(e =>
               {
                           if (e.EndDate>DateTime.Now )
                           {
                            @Html.ActionLink("Stop", "StopMedication", "Medication",
                                new { id = e.PrescriptionID }, new { @class = "standard button" })
                           }
                           else {
                               @Html.ActionLink("Renew", "RenewMedication", "Medication",
                                   new { id = e.PrescriptionID }, new { @class = "standard button" })
                                }
             });
       })
How can i get this work?

2 Answers, 1 is accepted

Sort by
0
Accepted
Mark
Top achievements
Rank 1
answered on 18 Oct 2011, 02:38 PM
I ran into this issue and found out that you can use "item" to reference the current row.  
This should work.

columns.Template(@<text>
@if (item.EndDate>DateTime.Now )
{
   @Html.ActionLink("Stop", "StopMedication", "Medication", new { id = item.PrescriptionID }, new { @class = "standard button" })
}
else 
{
   @Html.ActionLink("Renew", "RenewMedication", "Medication", new { id = item.PrescriptionID }, new { @class = "standard button" })
}
</text>);
0
HaBo
Top achievements
Rank 1
answered on 18 Oct 2011, 02:50 PM
Thank you for your Response. Though it works for conditional switching, I get a problem in comparing the dates.
because it is comparing with full date and time. I want to compare with just date 2011/110/18 not with the time.
When i try doing DateTime.Now.Date it throws an exception.
I am sure i will come up with a solution.
Once again thanks for your answer
Tags
Grid
Asked by
HaBo
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
HaBo
Top achievements
Rank 1
Share this question
or