ASP.NET Databind GridView 到数据源显示为空

发布于 2024-11-27 20:19:48 字数 1085 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み格子的夏天 2024-12-04 20:19:48

您可以检查 SelectCount 方法是否返回此处提到的整数吗?

ObjectDataSource 分页 -> GridView 中没有显示数据

can you check if SelectCount method is returning an Integer as mentioned here?

ObjectDataSource Paging -> no data displayed in GridView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文