码迷,mamicode.com
首页 > 编程语言 > 详细

使用JQuery插件,排序Gridview的某个字段

时间:2015-03-30 13:03:01      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

1. 前台代码

技术分享
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.10.2.js"></script>
    <script src="../../Scripts/jquery.tablesorter.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#GridView2").tablesorter();
        });
    </script>
    <style type="text/css">
        th {
            cursor: pointer;
            background-color: #dadada;
            color: Black;
            font-weight: bold;
            text-align: left;
        }
    </style>

</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView2" CellPadding="5" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField DataField="Item" HeaderText="Item" />
                    <asp:BoundField DataField="Price" HeaderText="Price" />
                </Columns>
            </asp:GridView>
        </div>
    </form>
</body>
</html>
View Code

2. 后台代码

技术分享
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Item"), new DataColumn("Price") });
                dt.Rows.Add("AItem", 20);
                dt.Rows.Add("BItem", 30);
                dt.Rows.Add("CItem", 40);
                dt.Rows.Add("DItem", 50);
                dt.Rows.Add("EItem", 60);
                dt.Rows.Add("FItem", 70);
                GridView2.DataSource = dt;
                GridView2.DataBind();


            }
            GridView2.UseAccessibleHeader = true;
            GridView2.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
View Code

注意:

需要下载JS插件,并引入插件

http://tablesorter.com/docs/#Download

查看Download里面的jquery.tablesorter.zip.

 

资料来源:

http://www.c-sharpcorner.com/Blogs/46650/how-to-do-sorting-in-gridview-on-client-side-using-jquery.aspx

 

使用JQuery插件,排序Gridview的某个字段

标签:

原文地址:http://www.cnblogs.com/songxia/p/4377445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!