views:

91

answers:

3

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.

A: 

Maybe try:

protected void Page_Load(object sender, EventArgs e)
{
    sgvConversionResults.DataBind();
}

Your code seems a bit convoluted though, any particular reason you are using an ObjectDataSource? Cause you can bind the datatable directly to the gridview in the codebehind

Luis
Thanks but have not helped
funky
A: 

onPostBack all variables get default values, sgvConversionResults save her structure but has clear rows. How I can save sgvConversionResults data onPostBack event???

funky
A: 

I transmit resultDataSource with ViewState and this work success!

funky