Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
Posted

1 solution

verify whether your event is already fired or not

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


Reference:
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/97e1256c-02c6-48dc-a8f8-c00bd1931b89[^]
 
Share this answer
 
Comments
GeoNav 16-Feb-13 22:14pm    
This code prevents loading of the control twice. Will this also prevent repeated firing of the OnPageINdexChanging event? Or do I have to check if the event was fired before allowing the event to fire?
I am adding the UserControl using mark up.
GeoNav 1-Mar-13 8:36am    
Anyone?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900