GridView分页不起作用

时间:2015-03-10 08:29:36

标签: c# asp.net gridview

我有一个旧的Web表单项目支持。我无法理解我在分页方面做错了什么。我有这段代码:

<asp:GridView ID="gvProducts" runat="server" 
    AllowSorting="True" AllowPaging ="true" PageSize="20"
    AutoGenerateColumns="False" DataKeyNames="products_id" CssClass="gridview" OnRowCommand="gvProducts_RowCommand"
    OnSelectedIndexChanging="gvProducts_SelectedIndexChanging"   
    OnRowDataBound="gvProducts_RowDataBound" 
    OnPageIndexChanging="gvProducts_PageIndexChanging"
    DataSourceID="dsSearchResult" >
    <PagerTemplate>
        <asp:GridViewPager ID="GridViewPager1" runat="server" />
    </PagerTemplate>

这是数据源:

<asp:ObjectDataSource ID="dsSearchResult" runat="server" SelectMethod="GetFindedProducts"
EnableViewState ="true" ViewStateMode="Enabled"
EnablePaging="True" TypeName="Paging.ResultSearch" 
SortParameterName="sortExpression">

这是页面索引更改方法:

protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gvProducts.PageIndex = e.NewPageIndex;
    gvProducts.DataBind();
}

当我点击分页按钮时,没有任何事情发生(只是页面数量发生了变化)。我试图找到解决方案,但所有的解决方案都不起作用。 这是我的SelectMethod:

public List<BOM.SearchProducts_pagedResult_ext> GetFindedProducts(int maximumRows, int startPageIndex, int startRowIndex, string sortExpression, string model, string param)
    {            
        SphinxClient client = new SphinxClient();
        string idProducts = client.GetIdProducts(model);
        SqlConnection connection = new SqlConnection(Globals.ConnectionString);
        string cmdText = "SearchProducts";
        SqlCommand command = new SqlCommand(cmdText, connection);
        command.CommandType = CommandType.StoredProcedure; // it's a default value
        command.CommandTimeout = 100;
        command.Connection = connection;
        command.Parameters.Add("@id_array", SqlDbType.NVarChar).Value = idProducts;
        DataSet ds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter(command);
        try
        {               
            connection.Open();         
            adapter.Fill(ds);
        }
        catch (Exception ex)
        {
            if (connection.State == ConnectionState.Open)
                connection.Close(); 
            throw new Exception("Can't get the list of products/GetProductsDataSet!", ex);
        }
        finally
        {
            connection.Close();
        }
        return TopagedResult_ext(ds);
    }

 public List<BOM.SearchProducts_pagedResult_ext> TopagedResult_ext(DataSet q)
    {
        DataRowCollection dr = q.Tables[0].Rows;
        List<BOM.SearchProducts_pagedResult_ext> searchResultArr = new List<BOM.SearchProducts_pagedResult_ext>();
        DataRow r;
        //BOM.SearchProducts_pagedResult searchResult;
        BOM.SearchProducts_pagedResult_ext searchResult_ext;
        for (int i=0; i < dr.Count; i++)
        {
            r = dr[i];
            searchResult_ext = fillData(r);
            searchResultArr.Add(searchResult_ext);
        }
        return searchResultArr;
    }

愿任何人帮助我吗?

0 个答案:

没有答案
相关问题