MVC显示表格,点击列头可以排序

原创 2016年08月31日 15:03:49

前台:

                        <table class="table table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th>序号</th>
                                    <th style="max-width: 100px; vertical-align:middle;">章名称</th>
                                    <th style="max-width: 150px;">节名称</th>
                                    <th>思维导图名称</th>
                                    <th>学员名称</th>
                                    <th>思维导图文件</th>
                                    <th>描述</th>
                                    @*<th>得分</th>*@
                                    <th>@Html.Partial("UndefinedPicSort", "sortCode", new ViewDataDictionary { { "ColumnName", "Score" },{"SortType",ViewData["SortType"]}, { "DisplayName", "得分" },{"TrainingId",ViewData["TrainingId"]},{"UnitContent",ViewData["UnitContent"]},{"ClassId",ViewData["ClassId"]},{"AccountId",ViewData["AccountId"]} })</th>
                                    <th>@Html.Partial("UndefinedPicSort", "sortCode", new ViewDataDictionary { { "ColumnName", "CreateDate" },{"SortType",ViewData["SortType"]}, { "DisplayName", "提交时间" },{"TrainingId",ViewData["TrainingId"]},{"UnitContent",ViewData["UnitContent"]},{"ClassId",ViewData["ClassId"]},{"AccountId",ViewData["AccountId"]} })</th>
                                    <th>是否是前三名</th>
                                    <th>评分</th>
                                </tr>
                            </thead>
                            <tbody>
                                @{
                                    var i = 1;
                                    string strAtt = string.Empty;
                                    //  章Id
                                    var chapterId = 0;
                                    var lastChapterId = 0;
                                    //  节Id
                                    var sectionId = string.Empty;
                                    var lastSectionId = string.Empty;
                                    foreach (CourseUndefinedPicInfe cupi in ViewBag.UndefinedPicList)
                                    {
                                        var accout = accountBll.GetModel(int.Parse(cupi.AuthorId), "");
                                        var baseInfo = baseBll.GetListModel(" Delflag=0 and AccountId=" + cupi.AuthorId);
                                        chapterId = cupi.Id;
                                        sectionId = string.IsNullOrEmpty(cupi.SecionId) ? "0" : cupi.SecionId;
                                        var spanChapter = ((List<CourseUndefinedPicInfe>)ViewBag.UndefinedPicList).FindAll(t => t.Id == cupi.Id).Count;
                                        var spanSection = ((List<CourseUndefinedPicInfe>)ViewBag.UndefinedPicList).FindAll(t => t.SecionId == cupi.SecionId).Count;
                                    <tr>
                                        <td class="contentMiddle">@i</td>
                                        @if (chapterId != lastChapterId)
                                        {
                                            <td id="ChapterTitle_@cupi.Id" rowspan="@spanChapter">@cupi.ChapterTitle</td>
                                        }
                                        @if (sectionId != lastSectionId)
                                        {
                                            <td id="SecionTitle_@cupi.SecionId" rowspan="@spanSection">@cupi.SecionTitle</td>
                                        }
                                        <td class="contentMiddle">@cupi.TaskTitle</td>
                                        <td class="contentMiddle">
                                            @if (baseInfo.Count > 0)
                                            {
                                                @baseInfo.First().RealName
                                            }
                                            else
                                            {
                                                @accout.Nickname
                                            }
                                        </td>

                                        <td class="contentMiddle">
                                            <div style="float: right; padding: 5px 0;" id="AttachNameList">
                                                @if (!string.IsNullOrEmpty(@cupi.AttList))
                                                {
                                                    //解析Json
                                                    JavaScriptSerializer jr = new JavaScriptSerializer();
                                                    var HomeWorkAtt = jr.Deserialize<List<Dianda.AP.Model.Course_UnitHomeWorkOther>>(@cupi.AttList);

                                                    if (HomeWorkAtt != null && HomeWorkAtt.Count > 0)
                                                    {
                                                        foreach (var AttItem in HomeWorkAtt)
                                                        {
                                                            strAtt += "0," + AttItem.AttName + "," + AttItem.AttPath + ":";                                                    
                                                    <a href="DownloadFile?FilePath=@AttItem.AttPath&FileName=@AttItem.AttName">@AttItem.AttName</a>
                                                    <br />
                                                        }
                                                    }
                                                }
                                            </div>
                                        </td>

                                        <td class="contentMiddle">@Html.Raw(cupi.HomeWorkContent)</td>
                                        <td class="contentMiddle">@cupi.Score</td>
                                        <td class="contentMiddle">@cupi.CreateTime</td>
                                        <td class="contentMiddle">@{if (cupi.IsTopThree == true) {<span>是</span>} else {<span>否</span>}}</td>
                                        <td class="contentMiddle">
                                            @if (!string.IsNullOrEmpty(@cupi.AuthorId) && @cupi.AuthorId != ViewBag.AccountId)
                                            {
                                                <input type="text" style="width:50px;" id="@cupi.HId" />
                                                <input type="button" onclick="submitScore(@cupi.HId)" value="确定" />
                                            }
                                        </td>
                                    </tr>
                                            i++;
                                            lastChapterId = cupi.Id;
                                            lastSectionId = cupi.SecionId;
                                    }
                                }
                            </tbody>
                        </table>

UndefinedPicSort:

@{
    //路由数据 如:Employee/Sortable?sortBy=EmployeeNO&ascending=False
    var routeData = new RouteValueDictionary {
    { "sortCode", ViewData["ColumnName"].ToString() }, 
    { "sortType", ViewData["SortType"].ToString() },
    {"trainingId",ViewData["TrainingId"].ToString()},
    {"unitContent",Dianda.Common.QueryString.Encrypt(ViewData["UnitContent"].ToString())},
    {"classId",ViewData["ClassId"].ToString()},
    {"accountId",Dianda.Common.QueryString.Encrypt(ViewData["AccountId"].ToString())},
    };


    var htmlAttributes = new Dictionary<string, object>();
    if (ViewData["SortType"].ToString() == "ASC")
    {
        htmlAttributes.Add("class", "sortAsc");//添加css样式
    }
    else
    {
        htmlAttributes.Add("class", "sortDesc");
    }
 
    @Html.ActionLink(
    ViewData["DisplayName"].ToString(), // 链接文本 
    Html.ViewContext.RouteData.Values["action"].ToString(), // Action 
    Html.ViewContext.RouteData.Values["controller"].ToString(), // Controller 
    routeData, // 路由数据
    htmlAttributes //HTML属性适用于超链接
    ) 
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

(三) MVC实现表格排序

出处:http://www.cnblogs.com/lukun/archive/2011/08/16/2139541.html 数据库为上文中数据库 1. 下载用于Linq中OrderBy中的类,...

【 MVC 】显示数据库数据表格

之前看。net之美很多地方都看不明白,但是今天重新看了一下,觉得很有感悟。 我演示了在一个HTML表格中格式化一系列数据库记录的两个方法。首先,我演示了如何直接在视图中格式化数据库记录。接下来,我示...

Gridview点击列头排序 .doc

  • 2012-10-22 09:47
  • 76KB
  • 下载

关于GridView点击列头排序

关于GridView列头点击排序 做ASP.NET Web项目开发,经常会和GridView打交道,免不了会根据需求要有列头点击排序的功能,在网上看了很多资料都没有把实例讲全,下面以linq原生语法...

[WPF]ListView点击列头排序功能实现

[WPF]ListView点击列头排序功能实现 这是一个非常常见的功能,要求也很简单,在Column Header上显示一个小三角表示表示现在是在哪个Header上的正序还是倒序就可以了...

C# listview 点击列头排序

#region 自定义变量 int currentCol = -1; bool sort; #endregion//列头点击事件 private vo...

C# ListView点击列头进行排序

/// /// This class is an implementation of the 'IComparer' interface. /// public cl...

Winform中DataGridView绑定List<T>数据源时,点击DataGridView列头不能自动排序解决方法

*********************************************方法一********************************************* 自定义...

C#点击ListView的列头时,对ListView排序

1.创建一个新的C#项目,窗体Form1会被默认创建。 2.向窗体添加一个ListView控件, 3.在Form1.cs中添加下面的代码: private ListViewColumnS...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)