This is a migrated thread and some comments may be shown as answers.

Disabling Paging during Edit

2 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grant Fletcher
Top achievements
Rank 1
Grant Fletcher asked on 06 May 2010, 09:03 PM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 May 2010, 06:13 AM
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.
0
Grant Fletcher
Top achievements
Rank 1
answered on 07 May 2010, 02:22 PM
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

 

Tags
Grid
Asked by
Grant Fletcher
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Grant Fletcher
Top achievements
Rank 1
Share this question
or