在GridView上将AllowSorting设置为True不会修改标头

时间:2018-01-19 15:10:35

标签: c# asp.net vb.net gridview

我正在尝试允许在GridView控件中进行排序。我将allowSorting设置为true,但它不会影响标题。

的GridView

<asp:GridView ID="gvClaimHistory" runat="server" AutoGenerateColumns="False" CssClass="table table-striped table-bordered table-condensed table-hover smaller-90"
    DataKeyNames="PolicyNumber,Block,Company" Width="100%" AllowPaging="false" AllowSorting="True">
    <Columns>
        <asp:TemplateField HeaderText="">
            <ItemTemplate>
                <asp:Image ID="expandCollapse" runat="server" AlternateText="" CssClass="plus" ImageUrl="~/images/plus.gif" ToolTip="Click to view Claim Details" />
                <asp:Panel ID="pnlClaimDetail" runat="server" Style="display: none">
                    <asp:GridView ID="gvClaimDetail" runat="server" AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-condensed"
                                                    OnRowDataBound="gvClaimDetail_RowDataBound">
                                                    <Columns>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.LineNumber %>" Visible="false">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblClaimLineNumber" runat="server" Text='<%# Eval("LineNumber")  %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="right" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.ServiceFromDate %>">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblClaimServiceFromDate" runat="server" Text='<%# Eval("LineIncurDate")  %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="center" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.ServiceToDate %>">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblClaimServiceToDate" runat="server" Text='<%# Eval("LineIncurToDate")  %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="center" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.PeriodOfPayment %>" Visible="false">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblDIPaymentPeriod" runat="server"><%# Eval("DIPayPeriodFrom") %> - <%# Eval("DIPayPeriodTo") %></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="center" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.PolicyInsuredName %>">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblClaimServiceDate" runat="server" Text='<%# StrConv(Eval("PolicyInsuredName"), VbStrConv.ProperCase)  %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="left" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.ChargeDescription %>">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblClaimServiceDate" runat="server" Text='<%# StrConv(Eval("ChangeTypeDescription"), VbStrConv.ProperCase)  %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="left" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.ProviderName%>">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblClaimServiceDate" runat="server" Text='<%# StrConv(Eval("ProviderName"), VbStrConv.ProperCase)  %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="left" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:Claim.ClaimAmount %>">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblClaimAmount" runat="server" Text='<%# FormatCurrency(Eval("ClaimAmount"),2,,false)  %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="right" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.PaidDate %>">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblReceivedDate" runat="server" Text='<%# Eval("PaidDate") %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="Center" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.CheckNumber %>">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblReceivedDate" runat="server" Text='<%# Eval("CheckNumber") %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="Center" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="<%$ Resources:ClaimDetail.Status %>">
                                                            <ItemTemplate>
                                                                <% If Me.InsuranceType = AgentResourceDL.DB2.ProductLines.Disability OrElse Me.InsuranceType = AgentResourceDL.DB2.ProductLines.DisabilityIncome _
 OrElse Me.InsuranceType = AgentResourceDL.DB2.ProductLines.GroupDisability Then%>
                                                                <asp:Label ID="lblClaimDetailStatus1" runat="server"> <b><%# StrConv(Eval("StatusDescription"), VbStrConv.ProperCase)%></b><br /> <%# StrConv(Eval("DenialMainDescription"), VbStrConv.ProperCase)%></asp:Label>
                                                                <%Else%>
                                                                <asp:Label ID="lblClaimDetailStatus2" runat="server"> <%# StrConv(Eval("DenialMainDescription"), VbStrConv.ProperCase)%></asp:Label>
                                                                <%End If%>
                                                            </ItemTemplate>
                                                            <ItemStyle HorizontalAlign="left" />
                                                        </asp:TemplateField>
                                                    </Columns>
                                                </asp:GridView>
                </asp:Panel>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.ClaimantNumber %>" Visible="false">
            <ItemTemplate>
                <asp:Label ID="lblClaimantNumber" runat="server" Text='<%# Eval("IndividualDRiderNumber") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.ClaimNumber %>">
            <ItemTemplate>
                <asp:Label ID="lblClaimNumber" runat="server" Text='<%# Eval("ClaimNumber") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.ReceivedDate %>">
            <ItemTemplate>
                <asp:Label ID="lblReceivedDate" runat="server" Text='<%# Eval("ReceivedDate") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.ClaimAmount %>">
            <ItemTemplate>
                <asp:Label ID="lblClaimAmount" runat="server" Text='<%# FormatCurrency(Eval("ClaimAmount"),2,,false)  %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="right" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.AmountDenied %>">
            <ItemTemplate>
                <asp:Label ID="lblAmountDenied" runat="server" Text='<%# FormatCurrency(Eval("DeniedAmount"),2,,false)  %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="right" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.Copay %>">
            <ItemTemplate>
                <asp:Label ID="lblCopay" runat="server" Text='<%# FormatCurrency(Eval("Copay"),2,,false)  %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="right" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.DeductibleAmount %>">
            <ItemTemplate>
                <asp:Label ID="lblDeductibleAmount" runat="server" Text='<%# FormatCurrency(Eval("DeductionAmount"),2,,false)  %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="right" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.LastPaidDate %>">
            <ItemTemplate>
                <asp:Label ID="lblLastPaidDate" runat="server" Text='<%# Eval("PaidDate") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="right" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.Insured %>" Visible="false">
            <ItemTemplate>
                <asp:Label ID="lblInsured" runat="server" Text='<%# StrConv(Eval("PolicyInsuredName"), VbStrConv.ProperCase)  %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Left" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.LastPaidAmount %>" Visible="false">
            <ItemTemplate>
                <asp:Label ID="lblLastPaidAmount" runat="server" Text=''></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="right" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.PaidAmount %>">
            <ItemTemplate>
                <asp:Label ID="lblPaidAmount" runat="server" Text='<%# FormatCurrency(Eval("PaidAmount"),2,,false) %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="right" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="<%$ Resources:Claim.Remarks %>">
            <ItemTemplate>
                <asp:Label ID="lblRemarks" runat="server" Text=''></asp:Label>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
    </Columns>
    <EmptyDataRowStyle CssClass="EmptyGridRow" />
    <EmptyDataTemplate>
        <div style="width: 98%; vertical-align: middle; padding: 1%;">
            <%= Resources.Common.ThereAreNoRecords.ToString()%>
        </div>
    </EmptyDataTemplate>
</asp:GridView>

添加排序表达式后出错

Google Developer Console

1 个答案:

答案 0 :(得分:2)

AllowSorting属性的MSDN文档(位于https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.allowsorting(v=vs.110).aspx)说:

  

要启用排序,请将AllowSorting属性设置为true。启用排序时,设置了SortExpression属性的每个列字段的标题文本将显示为链接按钮。

并进一步向下

  

如果通过Columns集合定义自己的列,则必须为每个列设置SortExpression属性;否则,该列将不会在标题中显示链接按钮。

您尚未为任何字段设置SortExpression,因此它们不可排序。