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

Last Row deleting problem

5 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 28 Sep 2009, 08:18 PM
Hi support,

I am attempting to institute a radgrid using a user control insert/edit form.  I am running into a problem with deletion of the last row in the grid on the last page.  For example, I have a situation where there are 4 records in the grid with a pagesize of 3. If I delete the 4th record then after the successful deletion, the paging is thrown out of whack and the grid can no longer find any records within the grid.  Moreover, the grid will not rebind either.  As I have a dropdown that controls the grid datasource which generally allows a different search. 

Note, since I have the paging as "always visible" the pager at the bottom is clickable and if I click the page number at the bottom it will reorient the grid and put everything into the right place.  I have tried a number of things and don't know where to go.
Without this always visible on, it is totally broken.

Josh

   

 I have copied and pasted the relevant code below
    <asp:Panel ID="PanelRadGrid" runat="server" style="table-layout:fixed; clear:both;" >               
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" PageSize="3" 
                AllowSorting="True" AllowPaging="True" AllowMultiRowSelection="False" 
                OnNeedDataSource="RadGrid1_NeedDataSource" 
                OnItemCommand="RadGrid1_ItemCommand"    
                OnInsertCommand="RadGrid1_InsertCommand"   
                OnUpdateCommand="RadGrid1_UpdateCommand" 
                OnDeleteCommand="RadGrid1_DeleteCommand" 
                OnItemCreated="RadGrid1_ItemCreated" 
                OnItemDataBound="RadGrid1_ItemDataBound" 
                Skin="Mastrr" 
                > 
                <PagerStyle Mode="NumericPages" HorizontalAlign="Center" AlwaysVisible="true" /> 
                <MasterTableView EnableTheming="false" InsertItemPageIndexAction="ShowItemOnCurrentPage" InsertItemDisplay="Bottom" DataKeyNames="PendForReviewKey" Width="100%" GridLines="None" AllowMultiColumnSorting="True" 
                      CurrentResetPageIndexAction="SetPageIndexToFirst" CommandItemDisplay="Bottom" TableLayout="Auto" ShowHeadersWhenNoRecords="true">  
                    <Columns> 
                        <telerik:GridTemplateColumn> 
                            <ItemTemplate> 
                                <asp:Button ID="ButtonEdit" runat="server" CommandName="Edit" CssClass="rgEdit" ToolTip="Edit" /> 
                            </ItemTemplate>   
                        </telerik:GridTemplateColumn>                      
                        <telerik:GridBoundColumn UniqueName="Person" SortExpression="Person" HeaderText="Person"   
                            DataField="Person">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn UniqueName="Product" SortExpression="Product" HeaderText="Product" 
                            DataField="Product">  
                        </telerik:GridBoundColumn>                           
                        <telerik:GridBoundColumn UniqueName="RenderOrg" SortExpression="RenderOrg" HeaderText="Rendering Organization" 
                            DataField="RenderOrg">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn UniqueName="BillingOrg" SortExpression="BillingOrg" HeaderText="Billing Organization" 
                            DataField="BillingOrg">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn UniqueName="BillingOrgTreeFlag" HeaderText="Org Tree Flag" 
                            DataField="BillingOrgTreeFlag">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn UniqueName="Diagnosis" SortExpression="Diagnosis" HeaderText="Diagnosis Code" 
                            DataField="Diagnosis">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn UniqueName="EffectiveDate" SortExpression="EffectiveDate" HeaderText="Effective Date" 
                            DataField="EffectiveDate">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn UniqueName="ExpirationDate" SortExpression="ExpirationDate" HeaderText="Expiration Date" 
                            DataField="ExpirationDate">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridTemplateColumn UniqueName="TemplateColumn">  
                           <ItemTemplate> 
                             <asp:Button ID="ButtonDelete" runat="server" CommandName="Delete" CssClass="rgDel" ToolTip="Delete" 
                              OnClientClick="javascript:if(!confirm('This action will delete the selected Pend For Review Record. Continue?')){return false;}"/>  
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn>                                                                                                                                                                                                                                            
                    </Columns> 
                    <EditFormSettings UserControlName="../AdminUC/ManagePendForReviewUC.ascx" EditFormType="WebUserControl">  
                     </EditFormSettings> 
                <CommandItemSettings AddNewRecordText=""   
                                     RefreshText="" />                       
                </MasterTableView> 
                <ClientSettings AllowKeyboardNavigation="True">    
                    <Selecting AllowRowSelect="False" />    
                </ClientSettings> 
        </telerik:RadGrid> 

    /// <summary>  
    /// The Delete event.  Occurs when user clicks the trash can icon on the edit form.  
    /// </summary>  
    /// <param name="source"></param>  
    /// <param name="e"></param>  
    protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)  
    {  
        Int16 pendForReviewKey = Convert.ToInt16(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["PendForReviewKey"]);  
        PendForReview.Delete(pendForReviewKey);  
 
        // Return to grid mode out of edit mode if that's where the user was.  
        e.Item.Edit = false;  
 
    } 

5 Answers, 1 is accepted

Sort by
0
Josh
Top achievements
Rank 1
answered on 30 Sep 2009, 06:03 PM
Bump!  I haven't heard any response from anyone on this.

Is this a bug?
0
Mira
Telerik team
answered on 01 Oct 2009, 03:05 PM
Hello Josh,

I suggest that you check whether the deleted row is the only one on the page and resetting the CurrentPageIndex in this case.
Please give it a try and tell me how it goes.

Best wishes,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Josh
Top achievements
Rank 1
answered on 04 Oct 2009, 04:23 PM
Mira,

I haven't been ignoring you.  I had attempted something like this already, but I've been distracted with other things.  I'll let you know when I try it.

Josh
0
Josh
Top achievements
Rank 1
answered on 05 Oct 2009, 03:46 PM

Mira,

Thank you.  I had tried to put in place your solution before with the following code:

        if (e.Item.OwnerTableView.Items.Count == 1)  
        {  
            e.Item.OwnerTableView.CurrentPageIndex = 1;  
        }  
 

However, this didn't work.  Then it occured to me that the PageIndex could possibly be zero based and it was!
The below code worked for me.  Thanks for your help.

        if (e.Item.OwnerTableView.Items.Count == 1)  
        {  
            e.Item.OwnerTableView.CurrentPageIndex = 0;  
        }  
 

Josh

0
Basel Nimer
Top achievements
Rank 2
answered on 08 Apr 2010, 07:47 PM
i almost have the same problem,

i have a user control that acts as a command panel, when deleting the last row (even that there are many other row - one page only), some of the controls inside that user control are not created correctly.

what can i do in my case? it is not the lastest :) row, but the last row.

Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Josh
Top achievements
Rank 1
Mira
Telerik team
Basel Nimer
Top achievements
Rank 2
Share this question
or