locked
Filtering and pagination to ObjectDataSource (SPGridView) RRS feed

  • Question

  • User558783729 posted

    I have SPGridView:

    <sp:SPGridView
        ID="grid"
        runat="server"
        AutoGenerateColumns="False"
        DataKeyNames="Year"
        AllowSorting="True"
        AllowPaging="True"
        PageSize="15"
        AllowFiltering="True"
        FilterDataFields="Year,Month,User_name,Department"
        FilteredDataSourcePropertyName="FilterExpression"
        FilteredDataSourcePropertyFormat="{1} = '{0}'"
        OnPageIndexChanging="absenceGrid_PageIndexChanging"

           >

    ....


    and in code a create a ObjectDataSource:


    protected void Page_Load(object sender, EventArgs e)
            {
                            grid.PagerTemplate = null;
                            Session["department"] = "test";
                            source = CreateDataSource();
                            Page.Controls.Add(source);
                            absenceGrid.DataSourceID = source.ID;     
            }


    private ObjectDataSource CreateDataSourcel()
            {
                ObjectDataSource source = new ObjectDataSource();
                source.ID = "DataSource";
                source.SelectMethod = "GetAll";
                source.TypeName = "ProjectOne.Data.Provider1";
                source.SelectParameters.Add("department", TypeCode.String, String.Empty);
                return source;
            }


    The i select a filterColumn the grid shows data ok, but then i change the page the data filter does not work. Grid show me data from current page without filer?


    Whats wrong help?

    Monday, December 6, 2010 6:33 AM

Answers

  • User1716267170 posted

    Just try to put the code within this block in page load event and try it again:

    if(!Page.IsPostBack) { // code here. }

    Thanks. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 10, 2010 2:33 AM

All replies

  • User558783729 posted

    Can someone help me?

    Tuesday, December 7, 2010 4:12 PM
  • User1716267170 posted

    Just try to put the code within this block in page load event and try it again:

    if(!Page.IsPostBack) { // code here. }

    Thanks. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 10, 2010 2:33 AM