RadGrid not updating!

10 posts, 0 answers
  1. Scott
    Scott avatar
    10 posts
    Member since:
    Jul 2012

    Posted 29 Dec 2009 Link to this post

    This code is loosely based on several of the demos. The main issue I'm having right now is that when I save data through my external form and call e.Item.OwnerTableView.Rebind() the RadGrid does not get updated. The only way to get the RadGrid to update is by paging or clicking the "Refresh" button.

    I'm calling e.Item.OwnerTableView.Rebind() and e.Item.Selected = true within the RadGrid_ItemCommand method.

    I have paste all code below incase I'm doing something stupid that's screwing everything up. I'm guessing it's a timing issue.

    Thanks for any help.

    ASPX
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="XmlHttpPanel3.aspx.cs" Inherits="XmlHttpPanel3" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title></title
        <telerik:radcodeblock id="RadCodeBlock" runat="server"
            <script type="text/javascript"
                //<![CDATA[
                function radGrid_RowSelected(sender, args) {
                    var key = args.getDataKeyValue("ContentId");
                    var panel = $find("<%=RadXmlHttpPanel.ClientID %>");
                    panel.set_value(key);
                }
                //]]> 
            </script> 
        </telerik:radcodeblock> 
    </head> 
    <body> 
        <form id="form1" runat="server"
            <div> 
                <asp:scriptmanager id="ScriptManager" runat="server" /> 
                <telerik:radcombobox id="RadComboBox" runat="server" skin="Telerik" datasourceid="ContentGroupDataSource" datatextfield="ContentGroupName" datavaluefield="ContentGroupId" autopostback="true" appenddatabounditems="true" onselectedindexchanged="RadComboBox_SelectedIndexChanged"
                    <items> 
                        <telerik:radcomboboxitem text="All" value="0" selected="true" /> 
                    </items> 
                </telerik:radcombobox> 
                <br /> 
                <style type="text/css"
                    .RadGrid_Telerik .rgFilterRow td { 
                        padding-top: 8px; 
                    } 
                </style> 
                <telerik:radgrid id="RadGrid" runat="server" skin="Telerik" width="250" allowpaging="true" allowfilteringbycolumn="true" autogeneratecolumns="false" oninit="RadGrid_Init" onneeddatasource="RadGrid_NeedDataSource" onitemcommand="RadGrid_ItemCommand"
                    <mastertableview commanditemdisplay="Top" editmode="EditForms" datakeynames="ContentId" clientdatakeynames="ContentId"
                        <columns> 
                            <telerik:gridboundcolumn uniquename="ContentName" datafield="ContentName" headertext="Name" filtercontrolwidth="200px" currentfilterfunction="Contains" autopostbackonfilter="true"></telerik:gridboundcolumn> 
                        </columns> 
                        <commanditemsettings addnewrecordtext="Add new content" /> 
                        <editformsettings editformtype="Template"
                            <formtemplate> 
                                <div style="background:#9DDF6C;padding-top:5px;"
                                    <table width="100%"
                                        <tr> 
                                            <td> 
                                                Name: 
                                            </td> 
                                            <td style="padding-left:2px;"
                                                <asp:textbox id="ContentName" runat="server" width="187px"></asp:textbox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td colspan="2" align="right" style="padding-right:10px;"
                                                <asp:linkbutton id="Insert" runat="server" commandname="PerformInsert" text="Insert"></asp:linkbutton> 
                                                &nbsp; 
                                                <asp:linkbutton id="Cancel" runat="server" commandname="Cancel" text="Cancel" causesvalidation="false" onclientclick="<%Eval(this.ClientFireCommandFunction(Telerik.Web.UI.RadGrid.CancelCommandName, String.Empty)) %>"></asp:linkbutton> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </div> 
                            </formtemplate> 
                        </editformsettings> 
                    </mastertableview> 
                    <clientsettings enablerowhoverstyle="true"
                        <selecting allowrowselect="true" /> 
                        <clientevents onrowselected="radGrid_RowSelected" /> 
                    </clientsettings> 
                    <groupingsettings casesensitive="false" /> 
                    <pagerstyle mode="NumericPages" showpagertext="false" pagebuttoncount="5" /> 
                </telerik:radgrid> 
                 
                <telerik:radxmlhttppanel id="RadXmlHttpPanel" runat="server" skin="Telerik" onservicerequest="RadXmlHttpPanel_ServiceRequest" loadingpanelid="RadAjaxLoadingPanel" enableclientscriptevaluation="true"
                    <asp:multiview id="MultiView" runat="server"
                        <asp:view id="SelectView" runat="server"
                            Select Content                     
                        </asp:view> 
                        <asp:view id="EditView" runat="server"
                            <asp:label id="ContentId" runat="server"></asp:label> 
                            <br /> 
                            <asp:textbox id="ContentName" runat="server"></asp:textbox> 
                            <br /> 
                            <telerik:radcombobox id="ContentGroup" runat="server" skin="Telerik" datatextfield="ContentGroupName" datavaluefield="ContentGroupId"></telerik:radcombobox> 
                            <br /> 
                            <asp:linkbutton id="SaveContent" runat="server" text="Save" onclick="SaveContent_Click"></asp:linkbutton> 
                        </asp:view> 
                    </asp:multiview>                 
                </telerik:radxmlhttppanel> 
                 
                <telerik:radajaxmanager id="RadAjaxManager" runat="server"
                    <ajaxsettings> 
                        <telerik:ajaxsetting ajaxcontrolid="RadComboBox"
                            <updatedcontrols> 
                                <telerik:ajaxupdatedcontrol controlid="RadComboBox" /> 
                                <telerik:ajaxupdatedcontrol controlid="RadGrid" loadingpanelid="RadAjaxLoadingPanel" /> 
                                <telerik:ajaxupdatedcontrol controlid="RadXmlHttpPanel" /> 
                            </updatedcontrols> 
                        </telerik:ajaxsetting> 
                        <telerik:ajaxsetting ajaxcontrolid="RadGrid"
                            <updatedcontrols> 
                                <telerik:ajaxupdatedcontrol controlid="RadComboBox" /> 
                                <telerik:ajaxupdatedcontrol controlid="RadGrid" loadingpanelid="RadAjaxLoadingPanel" /> 
                                <telerik:ajaxupdatedcontrol controlid="RadXmlHttpPanel" />                             
                            </updatedcontrols> 
                        </telerik:ajaxsetting> 
                    </ajaxsettings> 
                </telerik:radajaxmanager> 
                <telerik:radajaxloadingpanel id="RadAjaxLoadingPanel" runat="server"></telerik:radajaxloadingpanel> 
                <asp:objectdatasource id="ContentGroupDataSource" runat="server" typename="Abc.WD.InternationalStore.DataAccess.DataTableAdapters.ContentGroupInfoTableAdapter" selectmethod="GetDataByStoreId"
                    <selectparameters> 
                        <asp:parameter type="String" name="StoreId" defaultvalue="49D4B1F4-236B-DE11-870E-001A6465230E" /> 
                        <asp:parameter type="Int32" name="CultureId" defaultvalue="1033" /> 
                    </selectparameters> 
                </asp:objectdatasource> 
            </div> 
        </form> 
    </body> 
    </html> 
     


    CS
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Abc.WD.InternationalStore.DataAccess.DataTableAdapters; 
    using Abc.WD.InternationalStore.DataAccess; 
    using Telerik.Web.UI; 
     
    public partial class XmlHttpPanel3 : System.Web.UI.Page 
        protected void Page_Load(Object sender, EventArgs e) 
        {         
        } 
     
        protected void SaveContent_Click(Object sender, EventArgs e) 
        { 
            (RadGrid.Items[0] as GridDataItem).FireCommandEvent(RadGrid.UpdateCommandName, String.Empty); 
        } 
     
        protected void RadGrid_Init(Object sender, EventArgs e) 
        { 
            GridFilterMenu menu = RadGrid.FilterMenu; 
            Int32 i = 0; 
            while (i < menu.Items.Count) 
            { 
                if (menu.Items[i].Text == "NoFilter" || menu.Items[i].Text == "Contains"
                { 
                    i++; 
                } 
                else 
                { 
                    menu.Items.RemoveAt(i); 
                } 
            } 
        } 
     
        protected void RadGrid_ItemCreated(Object sender, GridItemEventArgs e) 
        { 
            if(e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                GridEditableItem item = e.Item as GridEditableItem; 
                 
                LinkButton insert = item.FindControl("Insert"as LinkButton; 
                insert.OnClientClick = String.Format("if(!$find('{0}').fireCommand('PerformInsert', '')) return false;", e.Item.OwnerID); 
     
                LinkButton cancel = item.FindControl("Cancel"as LinkButton; 
                cancel.OnClientClick = String.Format("if(!$find('{0}').fireCommand('CancelInsert','')) return false;", e.Item.OwnerID); 
            } 
        } 
     
        protected void RadGrid_ItemCommand(Object source, Telerik.Web.UI.GridCommandEventArgs e) 
        { 
            switch (e.CommandName) 
            { 
                case RadGrid.PageCommandName: 
                    { 
                        MultiView.ActiveViewIndex = 0; 
                    } 
                    break
                case RadGrid.InitInsertCommandName: 
                    { 
                        RadComboBox.Text = "All"
                        RadComboBox.Items[0].Selected = true
                        RadComboBox.Enabled = false
     
                        RadGrid.MasterTableView.FilterExpression = String.Empty; 
                         
                        foreach (GridColumn column in RadGrid.Columns) 
                        { 
                            column.CurrentFilterFunction = GridKnownFunction.Contains; 
                            column.CurrentFilterValue = String.Empty; 
                        } 
     
                        RadXmlHttpPanel.Value = String.Empty; 
                    } 
                    break
                case RadGrid.PerformInsertCommandName: 
                    { 
                        GridEditFormInsertItem item = e.Item as GridEditFormInsertItem; 
     
                        String contentName = ((TextBox)item.FindControl("ContentName")).Text; 
                        //String contentGroupId = ((RadComboBox)item.FindControl("ContentGroup")).SelectedValue; 
                        String contentGroupId = RadComboBox.FindItemByText("General").Value; 
     
                        ContentInfoTableAdapter adpater = new ContentInfoTableAdapter(); 
                        adpater.GetDataByInsert("49D4B1F4-236B-DE11-870E-001A6465230E", contentGroupId, contentName, String.Empty, 1033); 
     
                        RadComboBox.Enabled = true
     
                        RadGrid.AllowFilteringByColumn = true
     
                        if (RadGrid.Items.Count == RadGrid.PageSize) 
                        { 
                            RadGrid.CurrentPageIndex++; 
                        } 
                    } 
                    break
                case RadGrid.CancelCommandName: 
                    { 
                        RadComboBox.Enabled = true
                        RadGrid.CurrentPageIndex = 0; 
                        RadGrid.AllowFilteringByColumn = true
                    } 
                    break
                case RadGrid.UpdateCommandName: 
                    { 
                        String contentId = (RadGrid.SelectedItems[0] as GridDataItem).GetDataKeyValue("ContentId").ToString(); 
     
                        ContentInfoTableAdapter adapter = new ContentInfoTableAdapter(); 
                        Data.ContentInfoDataTable table = adapter.GetDataByUpdate(contentId, ContentName.Text, String.Empty, 1033, ContentGroup.SelectedValue); 
                        Data.ContentInfoRow content = table[0]; 
     
                        SetEditView(content); 
     
                        MultiView.ActiveViewIndex = 1; 
     
                        e.Item.OwnerTableView.Rebind(); 
                        e.Item.Selected = true
                    } 
                    break
            } 
        } 
     
        protected void RadComboBox_SelectedIndexChanged(Object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            MultiView.ActiveViewIndex = 0; 
            RadGrid.CurrentPageIndex = 0; 
            RadGrid.Rebind(); 
        } 
     
        protected void RadGrid_NeedDataSource(Object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
        { 
            ContentInfoTableAdapter adapter = new ContentInfoTableAdapter(); 
             
            if (RadComboBox.SelectedIndex == 0) 
            { 
                RadGrid.DataSource = adapter.GetDataByStoreId("49D4B1F4-236B-DE11-870E-001A6465230E", 1033); 
            } 
            else 
            { 
                RadGrid.DataSource = adapter.GetDataByContentGroupId(RadComboBox.SelectedValue, 1033); 
            } 
             
        } 
     
        protected void RadXmlHttpPanel_ServiceRequest(Object sender, RadXmlHttpPanelEventArgs e) 
        { 
            ContentInfoTableAdapter adapter = new ContentInfoTableAdapter(); 
            Data.ContentInfoDataTable table = adapter.GetDataByContentId(e.Value, 1033); 
            Data.ContentInfoRow content = table[0]; 
     
            SetEditView(content); 
            MultiView.ActiveViewIndex = 1; 
        } 
     
        void SetEditView(Data.ContentInfoRow content) 
        { 
            ContentId.Text = content.ContentId.ToString(); 
            ContentName.Text = content.ContentName; 
     
            ContentGroup.DataSource = ContentGroupDataSource; 
            ContentGroup.DataBind(); 
     
            RadComboBoxItem selectedContentGroup = ContentGroup.FindItemByValue(content.ContentGroupId.ToString()); 
            selectedContentGroup.Selected = true
            ContentGroup.Text = selectedContentGroup.Text; 
        } 
     

  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 30 Dec 2009 Link to this post

    Hello Scott,

    Try adding the following ajax setting to the RadAjaxManger control:

    <telerik:ajaxsetting ajaxcontrolid="SaveContent">  
        <updatedcontrols>  
            <telerik:ajaxupdatedcontrol controlid="RadGrid" loadingpanelid="RadAjaxLoadingPanel" />
        </updatedcontrols>  
    </telerik:ajaxsetting

    I hope it helps.

    Regards,
    Tsvetoslav
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jay Anderson
    Jay Anderson avatar
    12 posts
    Member since:
    Jan 2010

    Posted 05 Jan 2010 Link to this post

    I am having a similar issue. I am binding to an IList which is populated by a business object, using Linq. The Update, Insert, and Delete operations are all handled by events, not through Linq directly. The Insert and Delete operations both work as intended. I click the add new record button, enter information, and the grid updates properly, displaying the data after the AJAX call. Delete works also, dropping the row after the AJAX call.  The database is updated, also.

    However, with Update, the fields turn to edit boxes, you enter your changes, and those are visible. After Update is called, the fields change back to the original values (before typing the changes). The database is changed to the values that were typed in, but those aren't reflected in the grid. Only after a refresh is the current data displayed.
        private void BindWebDataGrid() 
        { 
            TelerikCSGConsultantRadGrid.DataSource = null
            csgAgreementEfcoUserXRefs = _csgAgreementEfcoUserXrefBL.GetByCsgAgreementId(Agreement.Id); 
            TelerikCSGConsultantRadGrid.DataSource = csgAgreementEfcoUserXRefs
            TelerikCSGConsultantRadGrid.DataBind(); 
        } 
     
     
        protected void TelerikCSGConsultantRadGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
        { 
            TelerikCSGConsultantRadGrid.DataSource = null
            csgAgreementEfcoUserXRefs = _csgAgreementEfcoUserXrefBL.GetByCsgAgreementId(Agreement.Id); 
            TelerikCSGConsultantRadGrid.DataSource = csgAgreementEfcoUserXRefs
        } 
     
        protected void TelerikCSGConsultantRadGrid_UpdateCommand(object source, GridCommandEventArgs e) 
        { 
            Efco.Business.Data.CsgAgreementEfcoUserXRef csgAgreementEfcoUserXRef = new CsgAgreementEfcoUserXRef(CurrentUser); 
            GridEditableItem item = e.Item as GridEditableItem; 
            try 
            { 
                csgAgreementEfcoUserXRef.AgreementId = Agreement.Id; 
                csgAgreementEfcoUserXRef.EfcoUserId = Convert.ToInt32((item["EfcoUserId"].Controls[0] as TextBox).Text); 
                csgAgreementEfcoUserXRef.CommissionPercentage = Convert.ToDecimal((item["CommissionPercentage"].Controls[0] as TextBox).Text); 
                csgAgreementEfcoUserXRef.Sequence = Convert.ToInt16((item["Sequence"].Controls[0] as TextBox).Text); 
     
                _csgAgreementEfcoUserXrefBL.Save(csgAgreementEfcoUserXRef); 
            } 
            catch (Exception ex) 
            { 
                TelerikCSGConsultantRadGrid.Controls.Add(new LiteralControl("Unable to update CSG Consultant. Reason: " + ex.Message)); 
            } 
        } 
     
        protected void TelerikCSGConsultantRadGrid_InsertCommand(object source, GridCommandEventArgs e) 
        { 
            Efco.Business.Data.CsgAgreementEfcoUserXRef csgAgreementEfcoUserXRef = new CsgAgreementEfcoUserXRef(CurrentUser); 
            GridEditableItem item = e.Item as GridEditableItem; 
            try 
            { 
     
                csgAgreementEfcoUserXRef.AgreementId = Agreement.Id;  
                csgAgreementEfcoUserXRef.EfcoUserId = Convert.ToInt32((item["EfcoUserId"].Controls[0] as TextBox).Text); 
                csgAgreementEfcoUserXRef.CommissionPercentage = Convert.ToDecimal((item["CommissionPercentage"].Controls[0] as TextBox).Text); 
                csgAgreementEfcoUserXRef.Sequence = Convert.ToInt16((item["Sequence"].Controls[0] as TextBox).Text); 
                csgAgreementEfcoUserXRef.RecordCreatedDate = DateTime.Now; 
                csgAgreementEfcoUserXRef.RecordCreatedEfcoUserId = CurrentUser.Id; 
                csgAgreementEfcoUserXRef.RecordUpdateDate = DateTime.Now; 
                csgAgreementEfcoUserXRef.RecordUpdatedEfcoUserId = CurrentUser.Id; 
     
                _csgAgreementEfcoUserXrefBL.Save(csgAgreementEfcoUserXRef); 
            } 
            catch (Exception ex) 
            { 
                TelerikCSGConsultantRadGrid.Controls.Add(new LiteralControl("Unable to insert CSG Consultant. Reason: " + ex.Message)); 
            } 
        } 
     
        protected void TelerikCSGConsultantRadGrid_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
        { 
            Efco.Business.Data.CsgAgreementEfcoUserXRef csgAgreementEfcoUserXRef = new CsgAgreementEfcoUserXRef(CurrentUser); 
            GridDataItem item = e.Item as GridDataItem; 
            try 
            { 
    Convert.ToInt32(item.OwnerTableView.DataKeyValues[item.ItemIndex]["EfcoUserId"]); 
     
                csgAgreementEfcoUserXRef = _csgAgreementEfcoUserXrefBL.GetById(Agreement.Id, 
                                                                               Convert.ToInt32(item["EfcoUserId"].Text)); 
                _csgAgreementEfcoUserXrefBL.Delete(csgAgreementEfcoUserXRef); 
            } 
            catch (Exception ex) 
            { 
                TelerikCSGConsultantRadGrid.Controls.Add(new LiteralControl("Unable to delete CSG Consultant. Reason: " + ex.Message)); 
            } 
        } 
     
    <Easi:EasiDataPanel ID="TelerikCSGConsultantDataPanel" runat="server"
        <telerik:RadGrid ID="TelerikCSGConsultantRadGrid" runat="server"  
            AutoGenerateColumns="False" GridLines="None"  
            ondeletecommand="TelerikCSGConsultantRadGrid_DeleteCommand"  
            oninsertcommand="TelerikCSGConsultantRadGrid_InsertCommand"  
            onneeddatasource="TelerikCSGConsultantRadGrid_NeedDataSource"  
            onupdatecommand="TelerikCSGConsultantRadGrid_UpdateCommand"  
            ShowStatusBar="True" > 
            <MasterTableView CommandItemDisplay="Top" EditMode="InPlace" > 
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px" /> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px" /> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="AgreementId" HeaderText="Agreement ID" DefaultInsertValue="" UniqueName="AgreementNumber"  
                        Visible="False"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EfcoUserId" HeaderText="Efco User ID" DefaultInsertValue="" UniqueName="EfcoUserId"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="CommissionPercentage" HeaderText="Commission Percentage" DefaultInsertValue=""  
                        UniqueName="CommissionPercentage"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Sequence" HeaderText="Sequence" DefaultInsertValue="" UniqueName="Sequence"
                    </telerik:GridBoundColumn> 
                    <telerik:GridButtonColumn CommandName="Select" Text="Select"  
                        UniqueName="column1"
                    </telerik:GridButtonColumn> 
                    <telerik:GridEditCommandColumn> 
                    </telerik:GridEditCommandColumn> 
                    <telerik:GridButtonColumn CommandName="Delete" Text="Delete"  
                        UniqueName="column"
                    </telerik:GridButtonColumn> 
                </Columns> 
                <EditFormSettings> 
                    <EditColumn UniqueName="EditCommandColumn1"
                    </EditColumn> 
                </EditFormSettings> 
            </MasterTableView> 
        </telerik:RadGrid> 
    </Easi:EasiDataPanel> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"  
        EnablePageHeadUpdate="False"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="TelerikCSGConsultantRadGrid"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="TelerikCSGConsultantRadGrid" LoadingPanelID="TelerikCSGConsultantDataPanel" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 

  5. Scott
    Scott avatar
    10 posts
    Member since:
    Jul 2012

    Posted 05 Jan 2010 Link to this post

    Tsvetoslav,

    Adding the additional ajax setting appears to have solved the problem.

    Thanks so much for your help.

    Scott
  6. Jay Anderson
    Jay Anderson avatar
    12 posts
    Member since:
    Jan 2010

    Posted 11 Jan 2010 Link to this post

    The code change suggested for Scott did not work in my case. Is there anything else to look at?

    Should I post this in it's own thread? I'm not sure what method would be preferred, because Scott's issue was very similar to mine.
  7. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 14 Jan 2010 Link to this post

    Hi Jay,

    Have you properly ajaxified your grid (as Scott's scenario was slightly different than yours). The ajax setting you need is as follows:

    <telerik:ajaxsetting ajaxcontrolid="TelerikCSGConsultantRadGrid>   
        <updatedcontrols>   
            <telerik:ajaxupdatedcontrol controlid="TelerikCSGConsultantRadGrid" loadingpanelid="RadAjaxLoadingPanel" /> 
        </updatedcontrols>   
    </telerik:ajaxsetting>

    If this doesn't help, could you specify where you are calling the BindWebDataGrid method and why?

    Thanks in advance.

    Regards,
    Tsvetoslav
    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.
  8. Jay Anderson
    Jay Anderson avatar
    12 posts
    Member since:
    Jan 2010

    Posted 14 Jan 2010 Link to this post

    I have the ajax code installed in an ajax manager at the bottom of the page.

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"  
        EnablePageHeadUpdate="False"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="TelerikCSGConsultantRadGrid"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="TelerikCSGConsultantRadGrid" LoadingPanelID="TelerikCSGConsultantDataPanel" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 

    I am calling the BindWebDataGrid in the Page_Load. If the page is a post back, the page_load is exited with a return statement. I have this in a method, because I was also trying to call the BindWebDataGrid after every insert/update/delete, by calling it in the corresponding events. This also did not work. Here is the rest of the code-behind for the page.

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Efco.Business.Data; 
    using Efco.Framework.WebControls.Base; 
    using Telerik.Web.UI; 
     
    public partial class Agreement_TelerikCSGConsultantWebControl : EfcoBaseControl 
        #region Private Members 
     
        private AgreementBL _agreementBL; 
        private CsgAgreementEfcoUserXRefBL _csgAgreementEfcoUserXrefBL; 
        private IList<CsgAgreementEfcoUserXRef> csgAgreementEfcoUserXRefs; 
     
        #endregion 
     
        #region Properties 
     
        public Agreement Agreement { get; set; } 
     
        public CsgAgreementEfcoUserXRef CsgAgreementEfcoUserXRef { get; set; } 
     
     
        #endregion 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            _agreementBL = new AgreementBL(CurrentUser); 
            _csgAgreementEfcoUserXrefBL = new CsgAgreementEfcoUserXRefBL(CurrentUser); 
     
            Agreement = _agreementBL.GetById(Agreement.Id); 
     
            if (Page.IsPostBack) 
            { 
                return; 
            } 
     
            if (Agreement == null) 
            { 
                Agreement = new Agreement(CurrentUser); 
            } 
            BindWebDataGrid(); 
        } 
     
        #region Binding Methods 
     
        public void Bind(Agreement agreement) 
        { 
            Agreement = agreement
        } 
     

    Thank you for the reply, and the help.
  9. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 15 Jan 2010 Link to this post

    Hello Jay,

    Please, note the difference between Simple and Advanced databinding as demonstrated in the linked online examples and the related help topics. In your case, you need to use Advanced databinding, i.e. bind your grid only in the NeedDataSource event.

    Regards,
    Tsvetoslav
    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.
  10. Jay Anderson
    Jay Anderson avatar
    12 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2010 Link to this post

    I have removed any calls to bind the grid, except for in the NeedDataSource event. I have also cleared the generic collection I am using for the data source before I repopulate the collection, and then assign it to the data source. I even tried a Thread.Sleep(1000), to see if the update was going through to the Linq data source before the collection was repopulated.  The value after the update is still the old value (before the update), not the updated value.  And the value in the Sql table is the new value.  After refreshing the page manually, the new value is displayed.

    I have verified by using breakpoints that the Page_Load fires, then the NeedDataSource, and the page is displayed. When you click the edit link on the row to update it, Page_Load fires, then NeedDataSource, then the page is displayed, with the fields in the update state (inline in my case). I then change the value, and click the Update link. Page_Load fires, then UpdateCommand (the change is saved to Linq business object using Save in this step),  then NeedDataSource, and the page is displayed.  The field that was updated displays the old value, not the updated value.  I then refresh the page (hit F5, refresh, etc.), Page_Load fires, then NeedDataSource, then the page is displayed.  Now the new value is displayed.

    EnableViewState is set to true on the RadGrid.

    I am unable to create a project to send, because this is built on an internal database, which is too large to send. Plus there is proprietary and private information in there. Also it is a large project, taking up a lot of space. I will have to see if I can recreate it in another environment, if that is required.

    If you have examples of using business objects to display in RadGrid, using a backend of Linq for a datasource, then I could take a look at a comparison between that and my project. I'm probably just missing a setting somewhere.
  11. Jay Anderson
    Jay Anderson avatar
    12 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2010 Link to this post

    I got this to work. I was not constructing the Update item properly. I used the example to update the event. Now the event gets the item from Sql first, updates those fields, and commits it to Sql. Now the updated items show up in the grid after the update link is clicked.

    Thanks for the help!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017