gridview自定义排序

效果如图:

首先允许排序:AllowSorting="True";开启gridview的排序事件onsorting="GridView1_Sorting",也可以双击sorting事件;其次是设置nrowdatabound="GridView1_RowDataBound",也可以双击GridView1_RowDataBound

关联排序表达式SortExpression="字段名称"

代码明细:

前台代码:

View Code
复制代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" Width="800px"
AllowSorting="True"
onrowdatabound="GridView1_RowDataBound" onsorting="GridView1_Sorting"
PageSize="15">
<PagerSettings Mode="NumericFirstLast"/>
<RowStyle BackColor="#EFF3FB"/>
<Columns>
<asp:BoundField DataField="CourseResID" HeaderText="课程ID"/>
<asp:BoundField DataField="CourseName" HeaderText="课程名" SortExpression="CourseName">
<ItemStyle Width="100px"/>
</asp:BoundField>
<asp:BoundField DataField="upTime" HeaderText="更新时间"
DataFormatString="{0:yyyy-MM-dd}" SortExpression="upTime">
<ItemStyle Width="160px" HorizontalAlign="Right"/>
</asp:BoundField>
<asp:BoundField DataField="UserName" HeaderText="用户名" SortExpression="UserName">
<ItemStyle Width="80px" ForeColor="#33CC33"/>
</asp:BoundField>
</Columns>

转载于:https://www.cnblogs.com/weihengblogs/p/3897122.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值