Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Gridview排序不工作_C#_Asp.net_Sorting_Gridview - Fatal编程技术网

C# Gridview排序不工作

C# Gridview排序不工作,c#,asp.net,sorting,gridview,C#,Asp.net,Sorting,Gridview,我尝试用优化的分页实现排序,但当我尝试排序时,什么也没有发生。排序标头的设计更改,仅此而已 Gridview: <div align="center"> <asp:ObjectDataSource ID="odsSupplier" runat="server" SelectMethod="GetSuppliers" TypeName="Supplier" EnablePaging="True" MaximumRowsParameterName="Pa

我尝试用优化的分页实现排序,但当我尝试排序时,什么也没有发生。排序标头的设计更改,仅此而已

Gridview:

<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>
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上

@user2103743将所有按钮字段更改为templatefield

是否在gridview之外使用UpdatePanel?不,我没有使用更新面板。当我单击标题时,该列将高亮显示,但gridview上显示的数据没有被排序
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;
}