@page @model NorthwindRazor.Pages.Products_ListForeachModel @{ ViewData["Title"] = "List of Products"; string bgColor = "#F7F6F3"; } @section AdditionalJavaScript { <script src="~/js/jqgrid-listforeach.js" asp-append-version="true"></script> <script type="text/javascript"> var urlAndMethod = '/Products/Products_ListForeach'; </script> } <h2>@ViewData["Title"]</h2> <br /><br /> <div id="errorConfirmationDialog"></div> <div id="errorDialog"></div> <a href="/Products/Products_Add?returnUrl=/Products/Products_ListForeach"><img src="@Url.Content("~/images/Add.gif")" alt="Add New Products" style="border: none;" /></a> <a href="/Products/Products_Add?returnUrl=/Products/Products_ListForeach">Add New Products</a> <br /><br /> <table class="gridviewGridLines" cellspacing ="0" cellpadding="8" style="width:100%;border-collapse:collapse;"> <tr style="color:#2E6E9E;background-color:#DFEFFC;font-weight:bold;"> @for (int i = 0; i < Model.ProductsFieldNames.GetLength(0); i++) { string fieldName = Model.ProductsFieldNames[i, 0]; string title = Model.ProductsFieldNames[i, 1]; if (Model.FieldToSortWithOrder.Contains(fieldName) && Model.FieldToSortWithOrder.Contains("asc")) { <td><a href="?sidx=@fieldName&sord=desc&handler=GridData" style="color:#2E6E9E;">@title</a>@if (Model.FieldToSortWithOrder == fieldName + " asc") {<img src="@Url.Content("~/images/ArrowUp.png")" alt="" />}</td> } else { <td><a href="?sidx=@fieldName&sord=asc&handler=GridData" style="color:#2E6E9E;">@title</a>@if (Model.FieldToSortWithOrder == fieldName + " desc") {<img src="@Url.Content("~/images/ArrowDown.png")" alt="" />}</td> } } <td> </td> <td> </td> </tr> @foreach (var item in Model.ProductsData) { <tr style="color:#333333; background-color:@bgColor;"> <td align="right">@item.ProductID</td> <td>@item.ProductName</td> <td align="right"><a href="~/Suppliers/Suppliers_Details?id=@item.SupplierID&returnUrl=/Products/Products_ListForeach">@item.SupplierID</a></td> <td align="right"><a href="~/Categories/Categories_Details?id=@item.CategoryID&returnUrl=/Products/Products_ListForeach">@item.CategoryID</a></td> <td>@item.QuantityPerUnit</td> <td align="right">@Convert.ToDouble(item.UnitPrice).ToString("C")</td> <td align="right">@item.UnitsInStock</td> <td align="right">@item.UnitsOnOrder</td> <td align="right">@item.ReorderLevel</td> <td align="center"><span><input type="checkbox" @(item.Discontinued ? "checked=\"checked\"" : "") disabled="disabled" /></span></td> <td align="center" style="width:30px;"> <a href="/Products/Products_Update?id=@item.ProductID&returnUrl=/Products/Products_ListForeach" title="Click to edit"><img src="@Url.Content("~/images/Edit.gif")" alt="" style="border:none;" /></a> </td> <td align="center" style="width:30px;"> <input type="image" id="imgDelete1" title="Click to delete" src="@Url.Content("~/images/Delete.png")" onclick="deleteItem('@item.ProductID');" style="border-style:none;" /> </td> </tr> bgColor = bgColor == "#F7F6F3" ? "White" : "#F7F6F3"; } <tr class="gridviewPagerStyle" align="center" style="background-color:#DFEFFC;"> <td colspan="12"> <table> <tr> @if (Model.CurrentPage > Model.NumberOfPagesToShow) { <td><a href="?sidx=@Model.FieldToSort&sord=@Model.FieldSortOrder&_page=1&handler=GridData" style="color:#000000;">< First</a></td> <td><a href="?sidx=@Model.FieldToSort&sord=@Model.FieldSortOrder&_page=@(Model.StartPage - 1)&handler=GridData" style="color:#000000;">...</a></td> } @for (int pageNumber = Model.StartPage; pageNumber <= Model.EndPage; pageNumber++) { if (pageNumber == Model.CurrentPage) { <td><span style="font-size:12px;">@pageNumber</span></td> } else { <td><a href="?sidx=@Model.FieldToSort&sord=@Model.FieldSortOrder&_page=@pageNumber&handler=GridData" style="color:#000000;">@pageNumber</a></td> } } @if (Model.EndPage < Model.TotalPages) { <td><a href="?sidx=@Model.FieldToSort&sord=@Model.FieldSortOrder&_page=@(Model.EndPage + 1)&handler=GridData" style="color:#000000;">...</a></td> <td><a href="?sidx=@Model.FieldToSort&sord=@Model.FieldSortOrder&_page=@Model.TotalPages&handler=GridData" style="color:#000000;">Last ></a></td> } </tr> </table> </td> </tr> </table>