如何通过单击上下图标在gridview中对数据进行排序? [英] How to sort data in gridview via clicking up-down icons ?

查看:93
本文介绍了如何通过单击上下图标在gridview中对数据进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了Matt Berseth的文章,也下载了此源.但是我不能做排序事件.一切正常,但排序无效.

一个YUI数据表样式化的GridView:

i read Matt Berseth article also i downloaded this source. But i can not do sorting event. Everything is ok but sorting is not working.

A YUI DataTable Styled GridView:

protected void GvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridView gridView = (GridView)sender;

            if (gridView.SortExpression.Length > 0)
            {
                int cellIndex = -1;
                foreach (DataControlField field in gridView.Columns)
                {
                    if (field.SortExpression == gridView.SortExpression)
                    {
                        cellIndex = gridView.Columns.IndexOf(field);
                        break;
                    }
                }

                if (cellIndex > -1)
                {
                    if (e.Row.RowType == DataControlRowType.Header)
                    {
                        //  this is a header row,
                        //  set the sort style
                        e.Row.Cells[cellIndex].CssClass +=
                            (gridView.SortDirection == SortDirection.Ascending
                            ? " sortascheader" : " sortdescheader");
                    }
                    else if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        //  this is an alternating row
                        e.Row.Cells[cellIndex].CssClass +=
                            (e.Row.RowIndex % 2 == 0
                            ? " sortaltrow" : "sortrow");
                    }
                }
            } 
        }


我的资料来源:


MY source:

<p>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
         <asp:GridView 
                        ID="gvCustomers" runat="server" CssClass="tablestyle" 
                        AllowSorting="true" 
                        OnRowDataBound="GvCustomers_RowDataBound" AutoGenerateColumns="false">
                        <AlternatingRowStyle CssClass="altrowstyle" />
                        <HeaderStyle CssClass="headerstyle" />
                        <RowStyle CssClass="rowstyle" />
                        <Columns>
                            <asp:BoundField HeaderText="Kategori" DataField="Category" SortExpression="Category" />
                            <asp:BoundField HeaderText="Tarih" DataField="Date" SortExpression="Date" />
                        </Columns>
                    </asp:GridView>
        </ContentTemplate>
        </asp:UpdatePanel>
</p>

推荐答案

如果对文章有疑问,应在正文下方提供的论坛中询问作者.上还有大量的MSDN和其他教程.
If you have a question about an article, you should ask the author in the forum provided below the main body. There''s also tons of MSDN and other tutorials on this.


这篇关于如何通过单击上下图标在gridview中对数据进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆