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