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

[Solved] Rad Grid not updating with new value after update

3 Answers 606 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay Anderson
Top achievements
Rank 1
Jay Anderson asked on 12 Jan 2010, 06:34 PM
I am using RadGrid in an ASP.NET AJAX control in VS2008, including it on a page with other controls.

I am binding to an IList which is populated by a business object, using Linq. There is no direct access to the tables, only to the collection. 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 (new values), but those aren't reflected in the grid. Only after a refresh is the current data displayed.

CodeBehind:
    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));  
        }  
    }  

ASP Page:
<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>  







3 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 15 Jan 2010, 11:07 AM
Hi Jay,

Could you verify that the ViewState of the RadGrid is enabled. Because if you  set EnableViewState="false" on some of the RadGrid parent controls or the Page the NeedDataSource event is fired before UpdateCommand and this will cause a similar issue.
Also it will be helpful if you could send us a simple runnable project that could be used for reproducing the problem. You could open a formal support ticket from your Telerik account and attach a ZIP file there. We will check it and advise you further. 

Regards,
Radoslav
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
Jay Anderson
Top achievements
Rank 1
answered on 15 Jan 2010, 01:45 PM
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.
0
Jay Anderson
Top achievements
Rank 1
answered on 15 Jan 2010, 07:31 PM
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!
Tags
Grid
Asked by
Jay Anderson
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Jay Anderson
Top achievements
Rank 1
Share this question
or