【问题标题】:Gridview Sorting not workingGridview排序不起作用
【发布时间】:2013-02-09 12:31:54
【问题描述】:

我尝试使用优化的分页来实现排序,但是当我尝试排序时,没有任何反应。排序标题的设计改变了,就是这样。

网格视图:

<div align="center">

     <asp:ObjectDataSource ID="odsSupplier" runat="server" SelectMethod="GetSuppliers"
        TypeName="Supplier" EnablePaging="True" MaximumRowsParameterName="PageSize" SelectCountMethod="GetRowsCount" StartRowIndexParameterName="StartRow" SortParameterName="sortBy">
    </asp:ObjectDataSource>


    <asp:GridView ID="supplierGridView" runat="server" AllowSorting="True" 
         CellPadding="4" DataSourceID="odsSupplier"
        ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="15" 
         Width="300px">

        <Columns>
            <asp:ButtonField ButtonType="button" CommandName="Ed" HeaderText="Edit" 
                Text="Edit">
                <ControlStyle Width="75px" />
                <HeaderStyle HorizontalAlign="Center" Width="75px" />
                <ItemStyle Width="75px" HorizontalAlign="Center" />
            </asp:ButtonField>

            <asp:ButtonField ButtonType="button" CommandName="Del" HeaderText="Delete" 
                Text="Delete">
                <ControlStyle Width="75px" />
                <HeaderStyle HorizontalAlign="Center" Width="75px" />
                <ItemStyle Width="75px" HorizontalAlign="Center" />
            </asp:ButtonField>
        </Columns>

        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerSettings Mode="NumericFirstLast" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
</div>

供应商类

public DataView GetSuppliers(int StartRow, int PageSize)
{
    return GetData(StartRow, PageSize, "EquipmentSupplierID");
}

public DataView GetSuppliers(int StartRow, int PageSize, string sortBy)
{
    return GetData(StartRow, PageSize, sortBy);
}

public DataView GetSuppliers(string sortBy)
{
    return GetData(int.MaxValue, 0, sortBy);
}

private DataView GetData(int StartRow, int PageSize, string sortBy)
{
    dbconn db = new dbconn();
    return db.getSupplierData(StartRow, PageSize, sortBy).DefaultView;
}

public int GetRowsCount()
{
    dbconn db = new dbconn();
    return db.getSupplierCount();
}

dbconn 类

public int getSupplierCount()
{
    open();
    setQuery("SELECT COUNT(*) AS Count FROM equipmentsupplier");
    MySqlDataReader msdr = executeReader();
    msdr.Read();
    int count = int.Parse(msdr["Count"].ToString());
    close();
    return count;
}

public DataTable getSupplierData(int StartRow, int PageSize, string sortBy)
{
    open();
    setQuery("SELECT * from equipmentsupplier ORDER BY ?SORT LIMIT ?StartRow, ?Total;");
    setParameter("StartRow", StartRow);
    setParameter("Total", PageSize);
    setParameter("SORT", sortBy);

    DataTable dt = new DataTable();
    dt.Load(executeReader());
    return dt;
}

当我对它进行排序时,查询返回了正确的数据,但它只是没有显示在我的 gridview 上。

【问题讨论】:

  • 您是否在网格视图之外使用 UpdatePanel?
  • 不,我没有使用更新面板。当我单击标题时,该列突出显示,但 gridview 上显示的数据未排序

标签: c# asp.net sorting gridview


【解决方案1】:

@user2103743 将所有按钮域更改为模板域

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多