Disabling Paging during Edit

3 posts, 0 answers
  1. Grant Fletcher
    Grant Fletcher avatar
    4 posts
    Member since:
    Apr 2010

    Posted 06 May 2010 Link to this post

    I have a page with a grid which allows paging by definition in the RadGrid tag.  I want to prevent the user from changing pages when they have initiated an edit because they will lose whatever changes they have entered on the form.  I have tried putting MasterTableView.AllowPaging = False in the NeedDataSource event handler.  This does take the paging controls off the page.  But, if the selected record is on anything but the first page of the form the record in Edit mode is the corresponding record on the first page.  Or, in other words, the user selects record 5 on the second page to edit but record 5 on the first page is put in edit mode.  The page works as expected for any record selected on the first page.

    What is the recommended way to disable paging when a record has been selected to edit while preserving the relationship of the record selected for editing by the user?

    Thanks, in advance, for any help.

    Grant
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 May 2010 Link to this post

    Hi Grant,

    You could easily achieve this by setting the GridPagerItem's Enabled property to false in the PreRender event of the grid. Try the following code.
    CS:
           
            protected void RadGrid1_PreRender(object sender, EventArgs e) 
            { 
                GridPagerItem pagerItem = (GridPagerItem)RadGrid1.MasterTableView.GetItems(GridItemType.Pager)[1]; 
              
                if (RadGrid1.EditIndexes.Count > 0) // Item is in the Edit Mode  
                    pagerItem.Enabled = false
                else 
                    pagerItem.Enabled = true
     
            } 

    Hope this would help you.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Grant Fletcher
    Grant Fletcher avatar
    4 posts
    Member since:
    Apr 2010

    Posted 07 May 2010 Link to this post

    Thanks, Princy.  Works perfectly.  For the benefit of any one looking for an answer to a similar question, what I did was

    1) Added the following to the tag <RadGrid ... > in the aspx code:

    OnPreRender

     

    ="RadGridRows_PreRender"

    2) Enhanced your PreRender event handler in the code behind, slightly, to apply the same logic when the grid is in insert mode:

     

     

    Protected Sub RadGridRows_PreRender(ByVal sender As Object, ByVal e As EventArgs)

     

     

        Dim pagerItem As GridPagerItem = DirectCast(RadGridRows.MasterTableView.GetItems(GridItemType.Pager)(1), GridPagerItem)

     

     

        If RadGridRows.EditIndexes.Count > 0 Then 'Grid is in edit mode so disable paging.

     

     

     

     

            pagerItem.Enabled =

    False

     

     

     

     

     

        Else

     

     

     

     

     

            If boolDisallowPaging Then 'Set in the ItemCommand event handler (InitInsert) 

     

     

     

     

                pagerItem.Enabled =

    False

     

     

     

     

     

            Else

     

     

     

     

                pagerItem.Enabled =

    True

     

     

     

     

     

            End If

     

     

     

     

     

        End If

     

     

     

     

     

    End Sub 'RadGridRows_PreRender

     

Back to Top