I am new to ASP.NET and I want to write a simple WebApplication using WebForms that connects to a Database and displays some data in a Grid (with paging). I use Visual Studio 2015
For displaying the data I use a GridView in combination with an ObjectDataSource.
I use EntityFramework and a method GetCustomer() that returns all Customers from a database.I use that method as SelectMethod
My question is:
Both controls, GridView an ObjectDataSource, have parameters for Paging and SelectMethod
Which control’s parameter for Paging and SelectMethod should I use if I want to use Model Binding?
Currently I’m using this:
GridView :<br>
AllowPaging = true<br>
PageSize = 10<br>
SelectMethod = ""<br>
DataSourceID = dsCustomers<br>
ObjectDataSource:<br>
ID = dsCustomers<br>
EnablePaging = false<br>
SelectMethod = GetCustomers ()<br>
MaximumRowParameterName = ""<br>
StartRowIndexParameterName = ""<br>
These settings work, the data is displyed and paging is working.
But I am not sure if this is the correct way to do it.
And if I change the settings for Paging and SelectMethod like so
GridView: <br>
AllowPaging = false<br>
PageSize = ""<br>
SelectMethod = GetCustomers()<br>
DataSourceID = dsCustomers<br>
ObjectDataSource:<br>
ID = dsCustomers<br>
EnablePaging = true<br>
SelectMethod = <br>
MaximumRowParameterName = ""<br>
StartRowIndexParameterName = ""<br>
I get an error :
DataSource or DataSourceID cannot be defined on 'gridViewCustomers' when it uses model binding.
If I remove DataSourceID from the GridView then I get
"A public method with the name 'GetCustomers' was either not found or there were multiple methods with the same name"