【发布时间】:2016-03-02 07:18:35
【问题描述】:
我想排序databoundGridView。我在UpdatePanel 的子网络表单中添加了GridView。以下是我的代码。
<form id="CategoryForm" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="CategoryID"
OnRowDataBound="OnRowDataBound" OnRowEditing="OnRowEditing" OnRowCancelingEdit="OnRowCancelingEdit"
OnRowUpdating="OnRowUpdating" OnRowDeleting="OnRowDeleting" OnPageIndexChanging="OnPageIndexChanging"
EmptyDataText="No records has been added." ShowFooter="true" CssClass="table table-hover table-striped"
AllowPaging="true" PageSize="6" AllowSorting="true" >
<PagerSettings Mode="NumericFirstLast" PageButtonCount="4" Position="Top" />
<Columns>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150">
<HeaderTemplate>
<asp:Label ID="filterName" Text="Name" runat="server"></asp:Label>
</br>
<asp:Button ID="btnNameSort" OnClick="btnSortName_Click" runat="server"></asp:Button>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblCatName" runat="server" Text='<%# Eval("CategoryName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCatName" runat="server" Text='<%# Eval("CategoryName") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtCatNameAdd" runat="server" ValidationGroup="validation"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtCatNameAdd" ValidationGroup="validation" ErrorMessage="Cannot Be Empty." />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="150">
<FooterTemplate>
<asp:Button class="btn btn-primary" ID="btnAdd" Text="Add" runat="server" ValidationGroup="validation" OnClick="Insert"></asp:Button>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" />
</Triggers>
</asp:UpdatePanel>
</form>
<asp:GirdView> 标签中声明的所有事件都是 CRUD 的通用事件。在代码中,我跳过了Details、Date 等的其他列。现在我想对 GridView 中的任何列进行排序。怎么做?谢谢...
【问题讨论】: