views:

56

answers:

2

Hello

I have this loop that renders a schedule with checkboxes for each entry like this:

              Monday    Tuesday.....
08:00-09:00     [ ]        [ ]...
10:00-11:00     [ ]        [ ]...

Using this code in my view:

    <% for (int i = 1; i < 10; i++)
   {%>
<tr>
    <td>
        xx:00 - xx:00
    </td>
    <% for (int currentDay = 1; currentDay <= 7; currentDay++)
       {  %>
    <td>
        <%=Html.CheckBox("TimeRange" + currentDay.ToString()) %>
    </td>
    <%} %>
</tr>
<% } %>

Now I need to check if, for example, 08:00 Tuesday exists in Model.Timetable, i.e DayOfWeek = 2 And StartTime = '08:00'.

So I need:

1) Check if current value exists in Model.Timetable 2) Set it to checked in that case 3) Set the value of the checkbox to Model.Timetable.StartTime

How is that done?

/M

A: 

there is a way in jQuery to set a check box to checked based on the value of the checkbox.

$(".schedule[value='01012009']").attr("checked", "checked");

.schedule is the class that you have assigned to the check box and the value needs to be unique. .schedule class doesn't need to exist in the style sheet. It's an identifier for all the check boxes that you are concerned with.

So now all you need to do is work out which times to check on.

I hope this gets you closer to a solution.

griegs
I cant use JQuery in this project
molgan