Listview DataPager 与 ObjectDataSource 问题
我在 Listview 中添加了 DataPager 控件。显示数据时没有问题。但是当我单击“下一页”按钮时,出现错误。
错误:除非指定 SelectMethod,否则 ObjectDataSource“ObjectDataSource2”不支持 Select 操作。
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
FillGrid();
}
private void FillGrid()
{
User user = new User();
user = (User)HttpContext.Current.Session["login"];
ObjectDataSource2.SelectMethod = "GetDetails";
ObjectDataSource2.SelectParameters.Add("Customer_ID", DbType.Int32, Convert.ToString(user.Customer_ID));
ObjectDataSource2.SelectParameters.Add("Selected_Period", DbType.String, Convert.ToString(Request.QueryString["period"]));
ObjectDataSource2.TypeName = "Online.Lib.Invoice";
}
代码旁边:
<asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource2">
<LayoutTemplate>
<asp:DataPager ID="DataPager1" PagedControlID="ListView1" runat="server">
<Fields>
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField FirstPageText="İlk" LastPageText="Son" NextPageText="İleri" PreviousPageText="Geri" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
</asp:ListView>
I was added the DataPager Control inside Listview. There is no problem while displaying the data. But When I click the Next page button I m getting error.
Error: The Select operation is not supported by ObjectDataSource 'ObjectDataSource2' unless the SelectMethod is specified.
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
FillGrid();
}
private void FillGrid()
{
User user = new User();
user = (User)HttpContext.Current.Session["login"];
ObjectDataSource2.SelectMethod = "GetDetails";
ObjectDataSource2.SelectParameters.Add("Customer_ID", DbType.Int32, Convert.ToString(user.Customer_ID));
ObjectDataSource2.SelectParameters.Add("Selected_Period", DbType.String, Convert.ToString(Request.QueryString["period"]));
ObjectDataSource2.TypeName = "Online.Lib.Invoice";
}
CodeBeside:
<asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource2">
<LayoutTemplate>
<asp:DataPager ID="DataPager1" PagedControlID="ListView1" runat="server">
<Fields>
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField FirstPageText="İlk" LastPageText="Son" NextPageText="İleri" PreviousPageText="Geri" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
</asp:ListView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的。您的 FillGrid() 运行良好,您可以通过 Page_Load 例程加载它的数据。当您单击 ListView 的“下一页”时,您正在执行回发。
..这意味着 FillGrid() 未加载(这是 ObjectDataSource 具有 Select 指令的位置)。这超出了我在上面的代码片段中看到的内容。在 IsPostBack 处理中犯这样的错误是很常见的。
Ok. Your FillGrid() works well and you can load it's data by the Page_Load routine. When you click "Next page" of the ListView, you're doing a PostBack.
..Which means FillGrid() aren't loaded (which is the place ObjectDataSource have it's Select instruction). That's out of what I can see in the code snippets above. Quite common to make such mistakes in IsPostBack handling.