locked
When the DataBoundControl has paging enabled, either the SelectMethod should return an IQueryable RRS feed

  • Question

  • User761356933 posted

    I have something odd going on. 

    This was working fine, until I added an update method to my code behind. I don't understand what its changed.

    My select method does return iqueryable supplier - but when I put I breakpoint it seems it never even enters the select method. Can someone help me out here as I have been stuck with this for days now.

    Error:

    When the DataBoundControl has paging enabled, either the SelectMethod should return an IQueryable<ItemType> or should have all these mandatory parameters : int startRowIndex, int maximumRows, out int totalRowCount

    Select method:

    // The return type can be changed to IEnumerable, however to support
            // paging and sorting, the following parameters must be added:
            //     int maximumRows
            //     int startRowIndex
            //     out int totalRowCount
            //     string sortByExpression
            public IQueryable<supplier> GridView1_GetData()
            {
    
                SupplierDBModel context = new SupplierDBModel();
                return (from s in context.suppliers
                        select s).AsQueryable();
            }

    Grid:

                    <asp:GridView ID="GridView1" CssClass="table table-hover table-striped" SelectMethod="GridView1_GetData" DeleteMethod="GridView1_DeleteItem" UpdateMethod="GridView1_UpdateItem" AllowPaging="True"  AllowSorting="True" ItemType="PrincePortalWeb.Models.supplier" runat="server" AutoGenerateEditButton="True" AutoGenerateDeleteButton="True"              
                AutoGenerateSelectButton="True"  AutoGenerateColumns="False" ShowFooter="True"  DataKeyNames="supplierid" >
                                         <Columns>
                             <asp:BoundField DataField="supplierid" HeaderText="ID" />
                            <asp:BoundField ApplyFormatInEditMode="True" DataField="suppliername" HeaderText="Customer">
                            <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                            <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="status" HeaderText="Status">
                            <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                            <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="whencompliant.date" HeaderText="When Compliant" />
                            <asp:BoundField DataField="reviewdate.date" HeaderText="Review Date" />
                            <asp:BoundField DataField="lastreviewedby" HeaderText="Reviewed By" />
                            <asp:BoundField DataField="webstatus" HeaderText="Portal Status" />
                        </Columns>

    Supplier context and class:

        public partial class SupplierDBModel : DbContext
        {
    
    
    
    
            public SupplierDBModel()
                : base("name=SupplierDBModel")
            {
    
    
                // Database.SetInitializer(new MigrateDatabaseToLatestVersion<SupplierDBModel, EF6Console.Migrations.Configuration>());
    
    
            }
    
            public virtual DbSet<supplier> suppliers { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
            }
    
        }
    
            public partial class supplier 
            {
    
    
                public int supplierid { get; set; }
    
                [Required]
                [StringLength(50)]
                public string suppliername { get; set; }
    
                [StringLength(50)]
                public string address1 { get; set; }
    
                [StringLength(50)]
                public string county { get; set; }
    
                [StringLength(50)]
                public string country { get; set; }
    
                [StringLength(50)]
                public string telephone { get; set; }
    
                [StringLength(50)]
                public string address2 { get; set; }
    
                [StringLength(11)]
                public string postcode { get; set; }
    
                [StringLength(20)]
                public string webstatus { get; set; }
    
               
                public status status { get; set; }
    
                [StringLength(50)]
                public string LastreviewedBy { get; set; }
    
                [Column(TypeName = "datetime2")]
                public DateTime Whencompliant { get; set; }
                [Column(TypeName = "datetime2")]
                public DateTime Reviewdate { get; set; }
    
    
    
            }
    
        public enum status
        {
            Compliant,
            In_Progress,
            Not_Started,
    
    
        }
    
        }

    Thank you

    Tuesday, July 10, 2018 8:01 AM

All replies

  • User761356933 posted

    OK

    I have found just having this in the code behind file throws the error. If I remove this method it works fine. I have put a breakpoint on this method and it doesn't enter it on load. So whats happening here? can anyone shed some light on this, I want to understand.

    If I comment this out its fine:

            protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
            {
    
                GridViewRow row = GridView1.Rows[e.NewEditIndex];
    
                TextBox txtName = row.FindControl("txtSupplierName") as TextBox;
    
                using (SupplierDBModel context = new SupplierDBModel())
                {
                    int supplierID = Convert.ToInt32(GridView1.DataKeys[e.NewEditIndex].Value);
                    supplier suppobj = context.suppliers.First(s => s.supplierid == supplierID);
                    suppobj.suppliername = txtName.Text.Trim();
                    context.SaveChanges();
    
                }
    
            }

    Tuesday, July 10, 2018 8:24 AM
  • User1724605321 posted

    Hi BluSky28,

    That is quite strange since the gridview even doesn't have the RowEditing event registered . In my opinion , it won't be the reason which leads to your error , it won't fire since it is not registered . Please double check your codes and try to find whether any other codes affect in this scenario .

    Best Regards,

    Nan Yu 

    Wednesday, July 11, 2018 2:14 AM