0

I have a gridview that should allow sorting on all columns and works well aside from the first column. All column headers are clickable and sortable. On the first column however the sortExpression doesnt work. This is happening throughout the program that I am working on. Here is a clip of the code I am using.

 <asp:GridView ID="gdvDeposit" runat="server" AutoGenerateColumns="False"
                            CssClass="table table-striped table-condensed table-hover table-bordered dataTable-paging"
                            SortedAscendingHeaderStyle-CssClass="sorting_asc" SortedDescendingHeaderStyle-CssClass="sorting_desc" PageSize="100" AllowPaging="True" AllowSorting="True"
                            DataSourceID="ldsDeposit">
                            <Columns>
                                <asp:TemplateField HeaderText="Deposit #" SortExpression="DepositCode" >
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblDepositNumber" Text='<%# Eval("DepositCode") %>'  />
                                        <asp:Label runat="server" Text='<%# Eval("Id") %>' Visible="false" />
                                        <asp:HyperLink runat="server" NavigateUrl='<%#  "~/Accounting/DepositEdit.aspx?Id=" + Eval("Id") %>'><i class="fa fa-pencil pull-right gdv-hover-icon" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"></i></asp:HyperLink>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="DepositTypeName" HeaderText="Type #" ReadOnly="true" SortExpression="DepositTypeName"></asp:BoundField>
                                <asp:BoundField DataField="DepositDate" HeaderText="Date" DataFormatString="{0:d}" ReadOnly="True" SortExpression="DepositDate"/>
                                <asp:BoundField DataField="Amount" HeaderText="Amount" ReadOnly="true" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="Right" SortExpression="Amount"></asp:BoundField>
                                <asp:BoundField DataField="PaymentsTotal" HeaderText="Payment Total" ReadOnly="true" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="Right" SortExpression="PaymentsTotal"></asp:BoundField>
                                <asp:BoundField DataField="NumberOfPayments" HeaderText="# of Payments" ReadOnly="true" SortExpression="NumberOfPayments"></asp:BoundField>
                                <asp:TemplateField HeaderText="Balanced" SortExpression="Balanced">
                                     <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblPaid" Visible='<%# Eval("Balanced")%>'><i class="fa fa-check text-center"></i></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Deposited" SortExpression="Deposited">
                                     <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                    <ItemTemplate>
                                        <asp:CheckBox runat="server" ID="chkSelect" Checked='<%# Eval("Deposited")%>' AutoPostBack="True" OnCheckedChanged="chkSelect_OnCheckedChanged"  />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
Derek Kelly
  • 71
  • 1
  • 4
  • 1
    Do you mean the first column that is clicked to be sorted or always the first column of the GridView? – VDWWD Aug 23 '16 at 19:21
  • It's always the first column of the Gridview. For now, to solve it, I am just putting in an empty column as a temporary workaround, however for aesthetic reasons would like to find a fix. – Derek Kelly Aug 23 '16 at 20:41
  • See http://stackoverflow.com/questions/7666230/asp-net-gridview-default-sorting-order. Solution there is to add this to Page_load: `if (String.IsNullOrEmpty(gdvDeposit.SortExpression)) gdvDeposit.Sort("DepositTypeName", SortDirection.Ascending);` – VDWWD Aug 23 '16 at 21:16
  • That solution was to change the sort direction. My issue is the first column doesn't register as a sorting field. The arrows are shown but the click handler seems to be missing and when I click on that column instead of sorting it highlights the text as if it is disabled or something of the like. – Derek Kelly Aug 24 '16 at 14:00

0 Answers0