ASP.NET Databind GridView 到数据源显示为空
我在 ASP.NET 页面上有一个 GridView,我试图将其绑定到一个对象数据源,该数据源已设置为映射到我创建的访问数据库的 vb 对象。但是,当我运行该页面时,网格视图显示为空。 ObjectDataSource 肯定正在返回数据。分页参数正在使其到达底层对象。一直到我到达 DataBind() 调用,一切似乎都很好。但网格显示为空。有趣的是,如果我使用返回数据库中所有记录的方法,网格填充得很好。仅当我尝试实现自定义分页时才不显示任何记录。我尝试过使用向导,尝试以图表方式设置它并运行时。无论我做什么,我都无法在网格中显示分页数据。
oDatasource = New ObjectDataSource()
oDatasource.EnablePaging = True
oDatasource.TypeName = "tblMessage"
oDatasource.SelectMethod = "GetTblMessageSubset"
oDatasource.SelectCountMethod = "SelectCount"
oDatasource.SelectParameters.Clear()
oDatasource.SelectParameters.Add("strCompanyID", strCompanyID)
oDatasource.SelectParameters.Add("strEmployeeID", strEmployeeID)
oDatasource.StartRowIndexParameterName = "startRowIndex"
oDatasource.MaximumRowsParameterName = "maximumRows"
GridView1.AllowPaging = True
GridView1.PageIndex = 0
GridView1.PageSize = 10
GridView1.PagerSettings.Visible = True
GridView1.EmptyDataText = "No Data........"
GridView1.PagerSettings.Mode = PagerButtons.Numeric
GridView1.AutoGenerateColumns = True
GridView1.DataSource = oDatasource
GridView1.DataBind()
I have a GridView on an ASP.NET page that I'm trying to bind to an object data source that I've set up to map to a vb object I made which accesses the DB. When I run the page, though, the gridview comes up empty. The ObjectDataSource is definitely returning data. The paging parameters are making it to the underlying object. All the way until I get to the DataBind() call everything seems fine. But the grid comes up empty. Funny thing is, if I use the method that returns all records in the DB, the grid populates just fine. Only when I try to implement custom paging does display no records. I've tried using the wizards, I've tried diagrammatically setting it up and run time. No matter what I do I can't get paged data to display in the grid.
oDatasource = New ObjectDataSource()
oDatasource.EnablePaging = True
oDatasource.TypeName = "tblMessage"
oDatasource.SelectMethod = "GetTblMessageSubset"
oDatasource.SelectCountMethod = "SelectCount"
oDatasource.SelectParameters.Clear()
oDatasource.SelectParameters.Add("strCompanyID", strCompanyID)
oDatasource.SelectParameters.Add("strEmployeeID", strEmployeeID)
oDatasource.StartRowIndexParameterName = "startRowIndex"
oDatasource.MaximumRowsParameterName = "maximumRows"
GridView1.AllowPaging = True
GridView1.PageIndex = 0
GridView1.PageSize = 10
GridView1.PagerSettings.Visible = True
GridView1.EmptyDataText = "No Data........"
GridView1.PagerSettings.Mode = PagerButtons.Numeric
GridView1.AutoGenerateColumns = True
GridView1.DataSource = oDatasource
GridView1.DataBind()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检查
SelectCount
方法是否返回此处提到的整数吗?ObjectDataSource 分页 -> GridView 中没有显示数据
can you check if
SelectCount
method is returning an Integer as mentioned here?ObjectDataSource Paging -> no data displayed in GridView