我是ASP.NET新手,我想用WebForms编写一个简单的WebApplication,它连接到数据库并在网格中显示一些数据(带有分页)。我使用2015
为了显示数据,我结合使用GridView和ObjectDataSource。
我使用EntityFramework和一个从数据库返回所有客户的方法GetCustomer()。
我的问题是:
这两个控件( GridView和ObjectDataSource )都有Paging and SelectMethod的参数。
如果我想使用SelectMethod,应该使用哪个控件的分页参数和Model Binding
目前我使用的是:
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>这些设置正常工作,数据被拆开,分页工作。
但我不知道这是否正确的做法。
如果我像这样更改Paging and SelectMethod的设置
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>我收到一个错误:
当DataSource或DataSourceID使用模型绑定时,不能在“gridViewCustomers”上定义。
如果我从DataSourceID中删除GridView,那么我就会得到
“没有找到名为'GetCustomers‘的公共方法,或者有多个名称相同的方法”
发布于 2016-06-08 08:24:44
在第一个例子中,您的做法是正确的。
PageSize)。SelectMethod、InsertMethod、DeleteMethod和UpdateMethod应该在ObjectDataSource.If上指定--您需要在SqlDataSource级别上将其更改为SqlDataSource,但是属性名称略有不同,例如SelectCommand、InsertCommand e.t.c。注意:ObjectDataSource的ObjectDataSource属性可以非常明确地配置为在GridView上启用分页,但它更复杂,而且多年来我从未见过有人这样做过GridView控件。不过,如果您对如何做到这一点感到好奇,请看一下这篇MSDN文章。
https://stackoverflow.com/questions/37695988
复制相似问题