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

Grid is not update after a delete action

2 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hans van Rijnswoud
Top achievements
Rank 2
Hans van Rijnswoud asked on 02 Feb 2009, 03:12 PM
Hi,

I have a simple grid with only one button to delete a row.
I try all example that a found (demo, forum, etc...) but it's the same.
The row is well deleted from the database but the grid is not update .
The method RadGrid1_NeedDataSource is well called after the delete method and the ViewState is well changed!
If i reload completely the page i see off course the change.

Please help;-)

Grid code :

            <asp:Panel ID="PanelOverviewPollAdvice" runat="server" SkinID="PageContent"
                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
                    <AjaxSettings> 
                        <telerik:AjaxSetting AjaxControlID="RadGrid1"
                            <UpdatedControls> 
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/> 
                            </UpdatedControls> 
                        </telerik:AjaxSetting> 
                    </AjaxSettings> 
                </telerik:RadAjaxManager> 
                <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" Width="75px" Transparency="25"><img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0;" /></telerik:RadAjaxLoadingPanel> 
                <br /> 
                 
                <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista" 
                     GridLines="None"  
                     AllowPaging="True"  
                     AllowSorting="True"  
                     Width="100%"  
                     AutoGenerateColumns="False" 
                     OnNeedDataSource="RadGrid1_NeedDataSource"  
                     AllowFilteringByColumn="true"  
                     PageSize="20" OnInit="RadGrid1_Init"  
                     OnItemCreated="RadGrid1_ItemCreated"  
                     OnDeleteCommand="RadGrid1_DeleteCommand" 
                     AllowAutomaticDeletes="true"
                     <PagerStyle AlwaysVisible="True" Mode="Slider" /> 
                     <MasterTableView  
                        GridLines="None"  
                        Width="100%"  
                        DataKeyNames="PollAdvisId"  
                        IsFilterItemExpanded="true"  
                        AllowFilteringByColumn="true"
                       <RowIndicatorColumn><HeaderStyle Width="22px" /> 
                       </RowIndicatorColumn> 
                       <ExpandCollapseColumn><HeaderStyle Width="22px" /> 
                       </ExpandCollapseColumn> 
                       <Columns> 
                           <telerik:GridBoundColumn AllowFiltering="false" UniqueName="PollAdvisId" HeaderText="ID" DataField="PollAdvisId"  ItemStyle-HorizontalAlign="Left"
                               <HeaderStyle Width="30px" HorizontalAlign="Left" /> 
                           </telerik:GridBoundColumn> 
                           <telerik:GridBoundColumn UniqueName="Email" HeaderText="E-mail" DataField="Email" ItemStyle-HorizontalAlign="Left"
                               <HeaderStyle HorizontalAlign="Left" /> 
                               <ItemStyle HorizontalAlign="Left" /> 
                           </telerik:GridBoundColumn> 
                           <telerik:GridBoundColumn UniqueName="Advis" HeaderText="Advies" DataField="Advis" ItemStyle-HorizontalAlign="Left"
                               <HeaderStyle HorizontalAlign="Left" /> 
                               <ItemStyle HorizontalAlign="Left" /> 
                           </telerik:GridBoundColumn> 
                           <telerik:GridDateTimeColumn UniqueName="LastUpdate" HeaderText="Datum" DataField="LastUpdate" ItemStyle-HorizontalAlign="Left" DataType="System.DateTime" DataFormatString="{0:dd MM yyyy}"
                                 <HeaderStyle HorizontalAlign="Left" /> 
                               <ItemStyle HorizontalAlign="Left" /> 
                           </telerik:GridDateTimeColumn>                      
                           <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete"  
                               CommandName="Delete" ButtonType="ImageButton"  
                               ConfirmText="Do you want to delete this Pool advies?"  
                               ConfirmDialogType="RadWindow" ConfirmTitle="Delete"   
                               ItemStyle-HorizontalAlign="Left" Visible="true" HeaderText="Wissen"
                               <ItemStyle HorizontalAlign="Left" /> 
                           </telerik:GridButtonColumn> 
                       </Columns> 
                      
                       </MasterTableView><FilterMenu EnableTheming="True" Skin="Vista"><CollapseAnimation Duration="200" Type="OutQuint" /></FilterMenu></telerik:RadGrid> 
                        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Skin="Vista"></telerik:RadWindowManager> 
            </asp:Panel> 



Here is my C# code. I don't work with DataTable!

/// <summary> 
        ///  
        /// </summary> 
        private void LoadGrid() 
        { 
            var pollAdvice = new Business.PollAdvis(); 
            List<Business.PollAdvis> _list = pollAdvice.SelectAll(); 
            ViewState["PollAdviceList"] = _list; 
            RadGrid1.DataSource = _list; 
            RadGrid1.MasterTableView.DataKeyNames = new[] { "PollAdvisId" }; 
 
            RadGrid1.DataBind(); 
        } 
 
 
 
/// <summary> 
        /// Delete an pollAdvice 
        /// </summary> 
        /// <param name="sender">object</param> 
        /// <param name="e">GridItemEventArgs</param> 
        protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e) 
        { 
            var item = (GridDataItem)e.Item; 
            string pollAdviceIdStr = item.OwnerTableView.DataKeyValues[item.ItemIndex]["PollAdvisId"].ToString(); 
            int _pollAdviceId = int.Parse(pollAdviceIdStr); 
            var _pollAdvice = new Business.PollAdvis(_pollAdviceId); 
            if (ViewState["PollAdviceList"] != null
            { 
                var _list = (List<Business.PollAdvis>) ViewState["PollAdviceList"]; 
                _list.Remove(_pollAdvice); 
                ViewState["PollAdviceList"] = _list; 
            } 
            _pollAdvice.Delete(_pollAdviceId); 
        } 
 
 
/// <summary> 
        ///  
        /// </summary> 
        /// <param name="source">object</param> 
        /// <param name="ex">GridNeedDataSourceEventArgs</param> 
        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs ex) 
        { 
            if (ViewState["PollAdviceList"] != null
            { 
                var _list = (List<Business.PollAdvis>)ViewState["PollAdviceList"]; 
                RadGrid1.DataSource = _list; 
            } 
        } 
 
 

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 03 Feb 2009, 07:23 AM
Hello Edwin,

I am afraid that we are not aware of such issue. From the code you posted I can see function LoadGrid. Can you tell when this function is called? If you are using NeedDataSource to populate RadGrid with data you don't need explicitly to call DataBind of RadGrid. NeedDataSource will be called whenever RadGrid to update its source as on DeleteCommand.

Please try removing this function and see whether it is working properly.

All the best,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Hans van Rijnswoud
Top achievements
Rank 2
answered on 03 Feb 2009, 08:11 AM
Hi Nikolay,

Thanks for your quick answer.
The LoadGrid was called from the Page_Load ( if(!Page.IsPostBack){LoadGrid();})
I Deleted the LoadGrid method and move this code inside the method NeedDataSource and it's work fine now.

Thanks again.


Tags
Grid
Asked by
Hans van Rijnswoud
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
Hans van Rijnswoud
Top achievements
Rank 2
Share this question
or