Listview DataPager 与 ObjectDataSource 问题

发布于 2024-09-05 18:19:38 字数 1522 浏览 10 评论 0原文

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

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

发布评论

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

评论(1

话少情深 2024-09-12 18:19:38

好的。您的 FillGrid() 运行良好,您可以通过 Page_Load 例程加载它的数据。当您单击 ListView 的“下一页”时,您正在执行回发。

if(!IsPostBack)      
  FillGrid();
}

..这意味着 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.

if(!IsPostBack)      
  FillGrid();
}

..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.

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