I am writing project which gets data from Data Acess Layer and show it in GridView.
The problem is to allow sorting by column. When I click on head of columnt following occurs following error:
Exception Details: System.Web.HttpException: GridView 'GridView1' Trigger Events Sorting, which has not been processed.
Here the .cs code:
public partial class Default: System.Web.UI.Page
{
EmployeesTableAdapter eta = new EmployeesTableAdapter();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = eta.GetData();
GridView1.DataBind();
}
}
}
Here the .aspx code(only gridview):
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/view.png"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="images/edit.png"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
Does someony know how to allow sorting by columns?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…