You are missing SortExpression
's in your BoundField
's as mentioned in the other answers.
You are also using a TemplateField
which, depending on what is generating your data, may require manual sorting beyond use of SortExpression
.
If this is the case, then to sort manually, one method is to add an OnSorting
callback to the GridView
, SortExpression
's to your fields and a method to callback in your code-behind.
This would result in markup and code similar to (untested):
<asp:GridView ID="gvOutlookMeldingen" runat="server"
AllowSorting="True"
OnSorting="gvOutlookMeldingen_Sorting"
AutoGenerateColumns="False"
AutoGenerateSelectButton="True"
onselectedindexchanged="GridView_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Melder" HeaderText="Melder" SortExpression="Melder" />
<asp:BoundField DataField="Onderwerp" HeaderText="Onderwerp" SortExpression="Onderwerp" />
<asp:TemplateField HeaderText="Omschrijving" SortExpression="Omschrijving">
<ItemTemplate>
<div style="overflow:auto; width: 500px; height: 200px;">
<asp:Label ID="lblOmschrijving" runat="server" Text='<%# Bind("Omschrijving")%>'></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Meldingsdatum" HeaderText="Meldingsdatum" SortExpression="Meldingsdatum" />
<asp:BoundField DataField="OutlookID" HeaderText="OutlookID" SortExpression="OutlookID" />
</Columns>
</asp:GridView>
...and:
protected void gvOutlookMeldingen_Sorting(object sender, GridViewSortEventArgs e)
{
switch (e.SortExpression)
{
case "Melder":
if (e.SortDirection == SortDirection.Ascending)
{
gvOutlookMeldingen.DataSource = // Asc query for Melder field;
gvOutlookMeldingen.DataBind();
}
else
{
gvOutlookMeldingen.DataSource = // Desc query for Melder field ;
gvOutlookMeldingen.DataBind();
}
break;
// case statements for your other fields.
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…