I have a fairly simple GridView. This is the markup for Columns:
<Columns>
<asp:TemplateField HeaderText="JD Name" SortExpression="FullName"
HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="180px" >
<ItemTemplate>
<asp:LinkButton CommandName="edt" CommandArgument='<%#Eval("JurisdictionID") %>' runat="server" Text='<%#Eval("FullName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="JD Abbreviation" ItemStyle-Width="200px" DataField="JDAbbreviation" SortExpression="JDAbbreviation"
HeaderStyle-HorizontalAlign="Center" />
<asp:TemplateField
HeaderStyle-HorizontalAlign="Center" >
<ItemTemplate>
<asp:LinkButton ID="lnkStat" CommandName="inac" CommandArgument='<%#Eval("JurisdictionID") %>'
runat="server" Text='<%#Utils.GetStatusString((bool) Eval("IsActive")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
However, when I click on of the columns for sorting, it first triggers a row command event and then comes to sorting event. Can anybody tell me what is the mistake I am doing? In the RowCommand argument I get the SortExpression. This is really funny for me!
Sortis arow command. Check out this MSDN GridView.RowCommand Event article for more details.In your row command event you should add an
ifstatement so you can determine when the row command code should execute. Use e.CommandName.