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

RadGrid not refreshing

5 Answers 574 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 08 Feb 2015, 03:40 PM
I have a grid with an form template for editing and adding.  The grid also has a deletebutton column to delete rows.  All the events are firing but the grid doesn't refresh after itemcommand completes its work after an insert, update or delete is performed on the database.  I've stepped through the code and rebind() is being called.  We bind to a list of objects.

This is the behavior I'm experiencing

Clicking Add
The edit form opens, I enter the data and press Save.  The data saves, the form does not close.  I then click Cancel, the form closes and the grid refreshes without a full postback,

Clicking the Edit icon in the row

The edit form opens, I modify the data and press Save. The data saves, the form does close (but only because I included Me.rgAccountGroupAuthorizations.MasterTableView.ClearEditItems()  The grid does not refresh.  If I click Cancel the form closes and the grid doesn't refresh.

Clicking the Delete icon in the row
After confirmation, the data is deleted but the grid doesn’t refresh.

I've isolated the code on its own page.  The page doesn't have any ajax proxy (we use master pages)  We would really prefer to use the form template feature rather than a custom edit page or user control. 

Here is the markup and codebehind

<telerik:RadGrid ID="rgAccountGroupAuthorizations"
                    OnNeedDataSource="rgAccountGroupAuthorizations_NeedDataSource"
                    OnItemDataBound="rgAccountGroupAuthorizations_ItemDataBound"
                    OnItemCommand="rgAccountGroupAuthorizations_ItemCommand"
                    Width="600"
                    Height="100%"
                    AllowFilteringByColumn="false"
                    AllowPaging="false"
                    AllowSorting="true"
                    AutoGenerateColumns="false"
                    Skin="Web20"
                    ShowHeader="true"
                    ShowFooter="false"
                    CellSpacing="0"
                    GridLines="Both"
                    BorderWidth="0"
                    EnableViewState="false"
                    runat="server" >
    <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true" EnableRowHoverStyle="true">
    </ClientSettings>
    <MasterTableView TableLayout="Fixed"
                     DataKeyNames="AuthorizationGroupID,OrganizationID"
                     ClientDataKeyNames="AuthorizationGroupID,OrganizationID"
                     CommandItemDisplay="Top"
                     AllowMultiColumnSorting="false"
                     AllowNaturalSort="false"
                     EnableViewState="true">
        <CommandItemTemplate>
            <div style="height: 30px; margin-left: 10px;">
                <div style="float: left;">
                    <asp:LinkButton ID="btnInserAuthorizationGroup" CommandName="initinsert" font-size="Larger" Font-Bold="true" runat="server" ><img style="border:0px;vertical-align:middle;" alt="" src="../Images/add.gif" /><span style="padding-left: 10px; padding-top: 20px;">Add New Permission Group</span></asp:LinkButton>
                </div>
            </div>
        </CommandItemTemplate>
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <table id="Table2" class="baseTable">
                    <tr>
                        <td class="col1">
                            <asp:Label AssociatedControlID="txtAuthorizationGroup" Text="Permission Group" runat="server" /><uc:rfm runat="server" />
                        </td>
                        <td>
                            <telerik:RadTextBox ID="txtAuthorizationGroup" Width="300" MaxLength="100" runat="server" />
                            <asp:RequiredFieldValidator ID="rfvtxtAuthorizationGroup" ControlToValidate="txtAuthorizationGroup" EnableClientScript="true" Display="Dynamic"
                                ValidationGroup="AuthorizationGroup" ForeColor="red" ErrorMessage="Required" runat="server" />
                        </td>
                    </tr>
                    <tr class="footer">
                        <td colspan="2">
                            <telerik:RadButton ID="btnSaveAuthorizationGroup" Text="Save Permission Group" CommandName="InsertAuthorizationGroup" ValidationGroup="AuthorizationGroup" runat="server" />  
                            <telerik:RadButton ID="btnSaveAuthorizationGorupCancel" Text="Cancel" CommandName="cancel" runat="server" />
                        </td>
                    </tr>
                </table>
            </FormTemplate>
        </EditFormSettings>
        <SortExpressions>
            <telerik:GridSortExpression FieldName="AuthorizationGroup" SortOrder="Ascending" />
        </SortExpressions>
        <Columns>
            <telerik:GridBoundColumn DataField="AuthorizationGroup" HeaderText="Permission Group Description" SortExpression="SortName" HeaderStyle-Font-Size="Larger" HeaderStyle-Width="180px" HeaderStyle-Font-Bold="true" ItemStyle-Font-Bold="true" ItemStyle-Font-Size="Larger">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditButton" EditImageUrl="../Images/edit.gif" HeaderText="Edit">
                <HeaderStyle HorizontalAlign="Center" ForeColor="#000000" Font-Bold="true" Width="50px" />
                <ItemStyle HorizontalAlign="Center" ForeColor="#000000" Font-Bold="true" Width="50px" />
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn ConfirmText="Delete this Permission Group?"
                                        ConfirmDialogType="RadWindow"
                                        ConfirmTitle="Delete"
                                        ButtonType="ImageButton"
                                        CommandName="Delete"
                                        ConfirmDialogHeight="160px"
                                        ConfirmDialogWidth="250px"
                                        UniqueName="DeleteButton"
                                        ImageUrl="../Images/delete.gif"
                                        HeaderText="Delete" >
                <HeaderStyle HorizontalAlign="Center" ForeColor="#000000" Font-Bold="true" Width="50px" />
                <ItemStyle HorizontalAlign="Center" ForeColor="#000000" Font-Bold="true" Width="50px" />
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Protected Sub rgAccountGroupAuthorizations_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
 
    Me.rgAccountGroupAuthorizations.DataSource = AuthorizationGroupManager.GetListOfAuthorizationGroupsByOrganizationID(Convert.ToInt32(Me.hidOrganizationID.Value))
 
End Sub
 
Protected Sub rgAccountGroupAuthorizations_ItemDataBound(sender As Object, e As GridItemEventArgs)
 
    Select Case True
        Case TypeOf e.Item Is GridEditFormInsertItem
 
        Case TypeOf e.Item Is GridEditFormItem
            Dim GridEditFormItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
            If GridEditFormItem.IsInEditMode Then
                Using AuthorizationGroup As AuthorizationGroup = DirectCast(GridEditFormItem.DataItem, AuthorizationGroup)
                    Dim txt As RadTextBox = DirectCast(GridEditFormItem.FindControl("txtAuthorizationGroup"), RadTextBox)
                    txt.Text = AuthorizationGroup.AuthorizationGroup
                End Using
                DirectCast(GridEditFormItem.FindControl("btnSaveAuthorizationGroup"), RadButton).Text = "Update Permission Group"
                DirectCast(GridEditFormItem.FindControl("btnSaveAuthorizationGroup"), RadButton).CommandName = "updateauthorizationgroup"
            End If
 
        Case TypeOf e.Item Is GridDataItem
            Dim GridDataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim AuthorizationGroupID As Int32 = Convert.ToInt32(GridDataItem.GetDataKeyValue("AuthorizationGroupID"))
            Dim imgbtn As ImageButton
            imgbtn = DirectCast(GridDataItem.FindControl("EditButton"), ImageButton)
            If imgbtn IsNot Nothing Then
            End If
            imgbtn = DirectCast(GridDataItem.FindControl("gbcDeleteButton"), ImageButton)
            If imgbtn IsNot Nothing Then
                imgbtn.CommandArgument = AuthorizationGroupID.ToString()
            End If
 
        Case TypeOf e.Item Is GridCommandItem
            Dim GridCommandItem As GridCommandItem = DirectCast(e.Item, GridCommandItem)
            Dim lnkb As LinkButton
            lnkb = DirectCast(GridCommandItem.FindControl("btnInserAuthorizationGroup"), LinkButton)
            If lnkb IsNot Nothing Then
 
            End If
 
    End Select
 
End Sub
 
Protected Sub rgAccountGroupAuthorizations_ItemCommand(sender As Object, e As GridCommandEventArgs)
 
    If TypeOf e Is GridCommandEventArgs And e.CommandName.ToLower = "delete" Then
        Dim GridDataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
        Using AuthorizationGroup As AuthorizationGroup = AuthorizationGroupManager.GetAuthorizationGroup(DirectCast(GridDataItem.DataItem, AuthorizationGroup).AuthorizationGroupID)
            AuthorizationGroupManager.Delete(AuthorizationGroup)
            Me.rgAccountGroupAuthorizations.Rebind()
        End Using
        Me.rgAccountGroupAuthorizations.Rebind()
 
    ElseIf TypeOf e.Item Is GridEditableItem Then
        Dim GridEditableItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        If Not GridEditableItem.IsInEditMode And e.CommandName.ToLower = "updateauthorizationgroup" Then
            Dim GridDataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim AuthorizationGroupID As Int32 = Convert.ToInt32(GridDataItem.GetDataKeyValue("AuthorizationGroupID"))
            Dim txt As RadTextBox = DirectCast(GridDataItem.EditFormItem.FindControl("txtAuthorizationGroup"), RadTextBox)
            Using AuthorizationGroup As AuthorizationGroup = AuthorizationGroupManager.GetAuthorizationGroup(AuthorizationGroupID)
                AuthorizationGroup.AuthorizationGroup = txt.Text
                AuthorizationGroupManager.Update(AuthorizationGroup)
            End Using
            txt.Text = ""
            Me.rgAccountGroupAuthorizations.MasterTableView.ClearEditItems()
            Me.rgAccountGroupAuthorizations.Rebind()
 
        ElseIf GridEditableItem.IsInEditMode And e.CommandName.ToLower = "insertauthorizationgroup" Then
            Dim GridEditFormInsertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
            Dim x As String = ""
            Dim txt As RadTextBox = DirectCast(GridEditFormInsertItem.FindControl("txtAuthorizationGroup"), RadTextBox)
            Using AuthorizationGroup As New AuthorizationGroup()
                AuthorizationGroup.OrganizationID = Convert.ToInt32(Me.hidOrganizationID.Value)
                AuthorizationGroup.AuthorizationGroup = txt.Text
                AuthorizationGroupManager.Insert(AuthorizationGroup)
            End Using
            txt.Text = ""
            Me.rgAccountGroupAuthorizations.MasterTableView.ClearEditItems()
            Me.rgAccountGroupAuthorizations.Rebind()
        End If
 
    End If
 
End Sub

5 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 11 Feb 2015, 02:39 PM
Hi Dan,

I have examined the provided code, however it would be hard to pinpoint the exact cause of the issue. In order to narrow the search would you try to disable AJAX by setting the EnableAjax property of RadAjaxManager to false. Check if there will be a server-side error thrown after this.

Additionally, in order to hide the InsertForm you can set the IsItemInserted property of the MasterTableView to false.

Moreover, would you try to use the default "Update" and "PerformInsert" commands. You can handle the custom logic using the OnUpdateCommand and OnInsertCommand events. Note that Update and Insert commands invoke Rebind() implicitly, you do not need to manually rebind RadGrid.

Check out the following resources for additional information on the matter:


Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dan
Top achievements
Rank 1
answered on 11 Feb 2015, 06:15 PM
I disabled Ajax, it had no effect.  I initially used the default command names and thought that might have been the issue which is why I changed them.  I did use them again and it had no effect.  Using OnUpdateCommand and OnInsertCommand had no effect.  The only suggestion that worked was setting IsItemInserted to false after an insert.

0
Viktor Tachev
Telerik team
answered on 16 Feb 2015, 11:16 AM
Hello Dan,

I am afraid that it would be hard to determine the exact cause of the issue without replicating it locally. Would you send us a runnable sample where the problem is replicated? This will enable us to investigate the issue locally and look for its cause.

You can open a support ticket and send the project as attachment.


Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jalal
Top achievements
Rank 1
answered on 08 Apr 2019, 12:41 PM

For anyone who wants to rebind grid from inside ItemCommand, instead of calling Rebind, just call DataBind like this:

RadGrid1_NeedDataSource(null, null);
RadGrid1.DataBind();

 

0
Jalal
Top achievements
Rank 1
answered on 08 Apr 2019, 12:43 PM

Instead of calling RadGrid1.Rebind, call it like this:

RadGrid1_NeedDataSource(null, null);
RadGrid1.DataBind();

 

Tags
Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Dan
Top achievements
Rank 1
Jalal
Top achievements
Rank 1
Share this question
or