Problem wth paging ObjectDataSource

Posted by funky on Stack Overflow See other posts from Stack Overflow or by funky
Published on 2010-04-27T15:08:56Z Indexed on 2010/04/28 7:53 UTC
Read the original article Hit count: 359

Filed under:
|
|

asp page code:

  <asp:ObjectDataSource runat="server" ID="odsResults" OnSelecting="odsResults_Selecting" />
    <tr><td>
    <wssawc:SPGridViewPager ID="sgvpPagerTop" runat="server" GridViewId="sgvConversionResults" />
    </td></tr>
    <tr>
        <td colspan="2" class="ms-vb">
            <wssawc:SPGridView 
                runat="server" 
                ID="sgvConversionResults" 
                AutoGenerateColumns="false"
                RowStyle-CssClass=""
                AlternatingRowStyle-CssClass="ms-alternating" 
                />
        </td>
    </tr>

Class code:

public partial class Convert : System.Web.UI.Page

{
   ...
   private  DataTable resultDataSource = new DataTable();
   ...

  protected void Page_Init(object sender, EventArgs e)
    {
        ...

        resultDataSource.Columns.Add("Column1");
        resultDataSource.Columns.Add("Column2");
        resultDataSource.Columns.Add("Column3");
        resultDataSource.Columns.Add("Column4");
        ...
        odsResults.TypeName = GetType().AssemblyQualifiedName;
        odsResults.SelectMethod = "SelectData";
        odsResults.SelectCountMethod = "GetRecordCount";
        odsResults.EnablePaging = true;
        sgvConversionResults.DataSourceID = odsResults.ID;
        ConversionResultsCreateColumns();
        sgvConversionResults.AllowPaging = true;
        ...
    }

    protected void btnBTN_Click(object sender, EventArgs e)
    {
        // add rows into resultDataSource
    }

    public DataTable SelectData(DataTable ds,int startRowIndex,int maximumRows)
    {
        DataTable dt = new DataTable();

        dt.Columns.Add("Column1");
        dt.Columns.Add("Column2");
        dt.Columns.Add("Column3");
        dt.Columns.Add("Column4");

        for (int i =startRowIndex; i<startRowIndex+10 ;i++)
        {   
            if (i<ds.Rows.Count)
            {
                dt.Rows.Add(ds.Rows[i][0].ToString(), ds.Rows[i][1].ToString(),
                ds.Rows[i][2].ToString(), ds.Rows[i][3].ToString());
            }
        }
        return dt;
    }

    public int GetRecordCount(DataTable ds)
    {
        return ds.Rows.Count;
    }

    protected void odsResults_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        e.InputParameters["ds"] = resultDataSource;

    }

}

On click BTN button resultDataSource receive some rows. Page reload and we can see result in sgvConversionResults. First 10 rows. But after click next page in pager we have message "There are no items to show in this view". When I try debug I find that after postBack page (on click next page) input params "ds" is blank, ds.Rows.Count = 0 and etc... As though resultDataSource became empty(( What do I do not correctly?.

Sorry my English.

© Stack Overflow or respective owner

Related posts about asp

Related posts about paging