PageIndexChanging UserControl中GridView中的事件问题 [英] PageIndexChanging Event problem in GridView in UserControl

查看:44
本文介绍了PageIndexChanging UserControl中GridView中的事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UserControl中有一个GridView控件。 AllowPaging =真。在将Page.DataSource声明为公共属性之后,在使用控件的页面中分配数据源。当我设置page.datasource属性时,我也调用GridView.DataBind。数据绑定工作正常,数据显示正确。



OnPageIndexChanging事件通过设置GridView.PageIndex = e.NewPageIndex来处理。在此之后我没有绑定数据,因为当我这样做时,网格中根本没有数据显示。



但是,当我点击页面索引时(说3)在使用控件的页面中,gridview页面不会改变。如果我点击另一个页面索引(比如说7),那么网格会导航到上一个索引(即3)!



我放了断点并发现了GridView_PageIndexChanging事件被处理两次,但每次在寻呼机中选择了正确的索引。否则,没有错误消息或其他重要观察。



有谁可以帮我解决这个问题?

I have a GridView Control in a UserControl. AllowPaging=True. The data source is assigned in page where the control is used, after declaring a Page.DataSource as public property. when i set the page.datasource property, I also call GridView.DataBind. Databinding works fine and data is displayed correctly.

OnPageIndexChanging event is handled by setting GridView.PageIndex=e.NewPageIndex. I am not binding the data after this, coz when I do that, no data is displayed in the grid at all.

But, when I click a page index (say 3) in a page where the control is used, the gridview page does not change. If i click another page index (say 7), then the grid navigates to the previous index (that is, 3)!

I put break points and found that the GridView_PageIndexChanging event is handled twice, but with correct index selected in the pager in each occasion. Otherwise, no error messages or other significant observations.

Can anyone help me resolve this?

推荐答案

验证你的活动是否已被解雇



verify whether your event is already fired or not

public partial class MyUserControl : UserControl
{
    private bool hadLoaded;
 
    public MyUserControl()
    {
        InitializeComponent();
 
        this.Loaded += delegate
        {
            if (!this.hadLoaded)
            {
                Console.WriteLine("Loaded");
                this.hadLoaded = true;
            }
        };
    }
}





参考:

http://social.msdn.microsoft.com/forums/en-US/wpf / thread / 97e1256c-02c6-48dc-a8f8-c00bd1931b89 [ ^ ]


这篇关于PageIndexChanging UserControl中GridView中的事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆