GridView 排序不起作用

发布于 2024-10-24 23:44:11 字数 3103 浏览 3 评论 0原文

请帮助我,我设置了Allowsorting =“true”,但排序在我的GridView中不起作用。我想要自动排序,即排序而不处理其事件。

这是aspx页面的代码:

<asp:GridView ID="gdvSignatureLines" runat="server" CssClass="Grid1" AutoGenerateColumns="False"
                        SkinID="PagedGridView" AllowPaging="True" AllowSorting="True" DataKeyNames="Id" 
                        onrowcommand="gdvSignatureLines_RowCommand" 
                        onrowdeleting="gdvSignatureLines_RowDeleting" 
                        onrowediting="gdvSignatureLines_RowEditing">
                        <PagerStyle CssClass="gridPager" HorizontalAlign="Right" />
                        <Columns>
                            <ucc:commandfieldcontrol headertext="Actions" showdeletebutton="true" buttontype="Image"
                                deleteimageurl="~/App_Themes/Default/images/delete.png" showeditbutton="true"
                                editimageurl="~/App_Themes/Default/images/edit.png" deleteconfirmationtext="Are you sure you want to delete?">
                                    <ItemStyle HorizontalAlign="Center" Width="60px" />
                             </ucc:commandfieldcontrol>
                            <asp:BoundField DataField="SortOrder" HeaderText="Line" SortExpression="SortOrder" />
                            <asp:TemplateField HeaderText="Type">
                                <ItemTemplate>
                                    <asp:Label ID="lblglTypeId" runat="server" Text='<%# Eval("GeneralLookup.LookupItem") %>'></asp:Label>
                                </ItemTemplate>  
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Label">
                                <ItemTemplate>
                                    <asp:Label ID="lblglLabelId" runat="server" Text='<%# Eval("GeneralLookup1.LookupItem") %>'></asp:Label>
                                </ItemTemplate>  
                            </asp:TemplateField>
                            <asp:BoundField DataField="Caption" HeaderText="Caption" SortExpression="Caption" />
                        </Columns>
                        <EmptyDataTemplate>
                            <div class="divEmptyListingGrid">
                                --- No Signature Line Exists ---
                            </div>
                        </EmptyDataTemplate>
                    </asp:GridView>

这是CS文件的代码:

protected void LoadSignatureList(int reportId, string reportName)
{
    lblHeading.Text = "Signature Line for " + reportName;
    ReportOptionsBO reportOptionsBO = new ReportOptionsBO();
    this.gdvSignatureLines.DataSource = reportOptionsBO.GetReportSignatureLineByReportId(reportId);
    this.gdvSignatureLines.DataBind();
}

当我单击“行”或“标题”列的标题时,没有任何反应。

我还有一个工作正常的网格。两者之间的区别在于,数据在运行时绑定到该网格。但另一个网格的数据源是预设的。

我当前的网格没有启用分页和启用排序这些选项。

请尽快提供帮助。

Please help me, I set Allowsorting="true" but sorting is not working in my GridView. I want automatic sorting i.e. sorting without handling its event.

Here is code of aspx page:

<asp:GridView ID="gdvSignatureLines" runat="server" CssClass="Grid1" AutoGenerateColumns="False"
                        SkinID="PagedGridView" AllowPaging="True" AllowSorting="True" DataKeyNames="Id" 
                        onrowcommand="gdvSignatureLines_RowCommand" 
                        onrowdeleting="gdvSignatureLines_RowDeleting" 
                        onrowediting="gdvSignatureLines_RowEditing">
                        <PagerStyle CssClass="gridPager" HorizontalAlign="Right" />
                        <Columns>
                            <ucc:commandfieldcontrol headertext="Actions" showdeletebutton="true" buttontype="Image"
                                deleteimageurl="~/App_Themes/Default/images/delete.png" showeditbutton="true"
                                editimageurl="~/App_Themes/Default/images/edit.png" deleteconfirmationtext="Are you sure you want to delete?">
                                    <ItemStyle HorizontalAlign="Center" Width="60px" />
                             </ucc:commandfieldcontrol>
                            <asp:BoundField DataField="SortOrder" HeaderText="Line" SortExpression="SortOrder" />
                            <asp:TemplateField HeaderText="Type">
                                <ItemTemplate>
                                    <asp:Label ID="lblglTypeId" runat="server" Text='<%# Eval("GeneralLookup.LookupItem") %>'></asp:Label>
                                </ItemTemplate>  
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Label">
                                <ItemTemplate>
                                    <asp:Label ID="lblglLabelId" runat="server" Text='<%# Eval("GeneralLookup1.LookupItem") %>'></asp:Label>
                                </ItemTemplate>  
                            </asp:TemplateField>
                            <asp:BoundField DataField="Caption" HeaderText="Caption" SortExpression="Caption" />
                        </Columns>
                        <EmptyDataTemplate>
                            <div class="divEmptyListingGrid">
                                --- No Signature Line Exists ---
                            </div>
                        </EmptyDataTemplate>
                    </asp:GridView>

Here is the code of CS file:

protected void LoadSignatureList(int reportId, string reportName)
{
    lblHeading.Text = "Signature Line for " + reportName;
    ReportOptionsBO reportOptionsBO = new ReportOptionsBO();
    this.gdvSignatureLines.DataSource = reportOptionsBO.GetReportSignatureLineByReportId(reportId);
    this.gdvSignatureLines.DataBind();
}

When I click on the Header of column "Line" or "Caption", nothing happens.

I have one more grid that is working fine. The difference between both is, data is bound to this grid on runtime. But the other grid's datasource is preset.

My current grid has not these options of Enable Paging and Enable Sorting.

Please help as soon as possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文