关于DataGrid的排序问题......在线等待!

conbell 2003-08-21 11:45:34
怎样实现点击DataGrid某一列的Header后,按照该列排序?
...全文
91 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
godblessyU 2003-08-21
  • 打赏
  • 举报
回复
将onsort..=true后,OnSortCommand写上事件,在服务器端写就可以了
chmodyou 2003-08-21
  • 打赏
  • 举报
回复
private void myDatagrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if(e.SortExpression!="")

BindData(e.SortExpression); }
yyinger007 2003-08-21
  • 打赏
  • 举报
回复
同意
gamp 2003-08-21
  • 打赏
  • 举报
回复
其他列也只要在aspx页面中指定SortExpression=“”就可以了
gamp 2003-08-21
  • 打赏
  • 举报
回复
在.aspx文件中添加排序事件!如:<asp:datagrid id="ItemGrid" OnSortCommand="ItemGrid_Sort"><Columns>
<asp:BoundColumn DataField="ItemID" SortExpression="ItemID" ReadOnly="True" HeaderText="编号">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" CssClass="title"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Height="20px" Width="30px"></ItemStyle>
</asp:BoundColumn>

然后在.asps.cs文件中写上:protected void ItemGrid_Sort(Object sender, DataGridSortCommandEventArgs e)
{
ItemGrid.Attributes["SortExpression"] = e.SortExpression.ToString();
BindGrid();
}
liudodo 2003-08-21
  • 打赏
  • 举报
回复
datagrid的属性选择允许排序
然后将SortCommand事件绑定到一下函数
private void ListDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
this.Bind();
if (ViewState["SortDirect"] == null || ViewState["SortDirect"].ToString() == "ASC")
{
ViewState["SortDirect"] = "DESC";
}
else
{
ViewState["SortDirect"] = "ASC";
}
conn.dv.Sort = e.SortExpression + " " + ViewState["SortDirect"];
ListDataGrid.DataBind();
Pagination();
}
conbell 2003-08-21
  • 打赏
  • 举报
回复
sorry,问题已解决,谢谢各位大虾!
conbell 2003-08-21
  • 打赏
  • 举报
回复
我试了一下以上的方法好象不行,谁能给我发个DEMO给我,感激不尽!
lutl@golden-tech.com.cn

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧