Hi, i have a hierarchicaldatagrid that i bind to a generic collection using the grids datasource property and databind method. This grid has child grids as well so i make the datasource assignment in each page load.
I added a row updating event method that is hit whenever i exit a cell that i edited. In the rowupdating event i update my database with the value from the cell in the grid. After the save to the database the value in the grid reverts back to the old value, so if my value was 123 and i change it in the cell to 456 the grid reverts to 123 after the postback and the db says 456.
I'm not understanding why the grid is reverting back to the old value. Below is the grid code and the code behind for the save.
protected void Page_Load(object sender, EventArgs e) {
if (Session["appsDTO"] != null) { List<AppUpdateDto> apps = (List<AppUpdateDto>)Session["appsDTO"]; WebHierarchicalDataGrid1.DataSource = apps; WebHierarchicalDataGrid1.DataBind(); }
}
protected void WebHierarchicalDataGrid1_RowUpdating(object sender, Infragistics.Web.UI.GridControls.RowUpdatingEventArgs e) {
try { // if DTO object is dirty, map to Business object and Save if (Boolean.Parse(e.Values["ApplicationUpdateSearchIsDirty"].ToString())) MapAndSave(e.Values); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
<script type="text/javascript"> function GridRowUpdate() { var grid = $find("WebHierarchicalDataGrid1"); grid.get_gridView().get_behaviors().get_editingCore().commit(); }
</script>
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" AutoGenerateBands="False" AutoGenerateColumns="False" DataKeyFields="ApplicationId" Height="350px" Width="1147px" EnableDataViewState="True" onrowupdated="WebHierarchicalDataGrid1_RowUpdated" onrowupdating="WebHierarchicalDataGrid1_RowUpdating" StyleSetName="Nautilus" EnableViewState="False"> <Columns> <ig:BoundDataField DataFieldName="ApplicationId" Key="ApplicationId"> <Header Text="ApplicationId" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="ApplicationSatus" Key="ApplicationStatusCd"> <Header Text="ApplicationStatus" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="PolicyNumber" Key="PolicyNumber"> <Header Text="PolicyNumber" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="ClientName" Key="ClientName"> <Header Text="ClientName" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Carrier" Key="CarrierId"> <Header Text="CarrierId" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Source" Key="Source"> <Header Text="Source" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="ProducerName" Key="ProducerName"> <Header Text="ProducerName" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="ApplicationStatusDate" Key="ApplicationStatusDate"> <Header Text="ApplicationStatusDate" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="PolicyEffectiveDate" Key="PolicyEffectiveDate"> <Header Text="PolicyEffectiveDate" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="PolicyEffectiveEndDate" Key="PolicyEffectiveEndDate"> <Header Text="PolicyEffectiveEndDate" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="ApplicationUpdateSearchIsDirty" Hidden="true" Key="ApplicationUpdateSearchIsDirty"> <Header Text="ApplicationUpdateSearchIsDirty" /> </ig:BoundDataField> </Columns> <Bands> <ig:Band AutoGenerateColumns="False" DataMember="ApplicationProductLinks" Key="ApplicationProductLinks" DataKeyFields="ApplicationProductLinkId"> <Columns> <ig:BoundDataField DataFieldName="ApplicationId" Hidden="true" Key="ApplicationId"> <Header Text="ApplicationId" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="ApplicationProductLinkId" Hidden="true" Key="ApplicationProductLinkId"> <Header Text="ApplicationProductLinkId" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Product" Key="ProductId"> <Header Text="ProductId" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Lob" Key="LobId"> <Header Text="LobId" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="SubPremAmt" Key="SubPremAmt"> <Header Text="SubPremAmt" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="SubAnnPrem" Key="SubAnnPrem"> <Header Text="SubAnnPrem" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="SubAnnRev" Key="SubAnnRev"> <Header Text="SubAnnRev" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FinPremAmt" Key="FinPremAmt"> <Header Text="FinPremAmt" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FinAnnPrem" Key="FinAnnPrem"> <Header Text="FinAnnPrem" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FinAnnRev" Key="FinAnnRev"> <Header Text="FinAnnRev" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="AppProdLinkUpdateSearchIsDirty" Hidden="true" Key="AppProdLinkUpdateSearchIsDirty"> <Header Text="AppProdLinkUpdateSearchIsDirty" /> </ig:BoundDataField> </Columns> </ig:Band> </Bands> <Behaviors> <ig:Selection RowSelectType="Single" CellClickAction="Row" Enabled="true" /> <ig:EditingCore EnableInheritance="True" AutoCRUD="False"> <Behaviors> <ig:CellEditing EnableInheritance="True"> <ColumnSettings> <ig:EditingColumnSetting ColumnKey="ApplicationId" ReadOnly="true" /> <ig:EditingColumnSetting ColumnKey="ClientName" ReadOnly="true" /> <ig:EditingColumnSetting ColumnKey="Source" ReadOnly="true" /> <ig:EditingColumnSetting ColumnKey="ProducerName" ReadOnly="true" /> <ig:EditingColumnSetting ColumnKey="CarrierId" EditorID="ddpCarrier" /> <ig:EditingColumnSetting ColumnKey="ApplicationStatusCd" EditorID="ddpAppStatus" /> </ColumnSettings> <CellEditingClientEvents ExitedEditMode="GridRowUpdate" /> <EditModeActions MouseClick="Single" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Paging> </ig:Paging> <ig:Sorting> </ig:Sorting> <ig:Activation> </ig:Activation> </Behaviors> <EditorProviders> <ig:DropDownProvider ID="ddpCarrier"> <EditorControl DataSourceID="odsCarrier" DropDownContainerMaxHeight="200px" TextField="Carrier" ValueField="CarrierId" EnableAnimations="False" EnableDropDownAsChild="False"> <DropDownItemBinding TextField="Carrier" ValueField="CarrierId" /> </EditorControl> </ig:DropDownProvider> <ig:DropDownProvider ID="ddpAppStatus"> <EditorControl DataSourceID="odsApplicationStatus" DropDownContainerMaxHeight="200px" TextField="ApplicationStatus" ValueField="ApplicationStatusCd" EnableAnimations="False" EnableDropDownAsChild="False"> <DropDownItemBinding TextField="ApplicationStatus" ValueField="ApplicationStatusCd" /> </EditorControl> </ig:DropDownProvider> <ig:DropDownProvider ID="ddpProduct"> <EditorControl DataSourceID="odsProducts" DropDownContainerMaxHeight="200px" TextField="Product" ValueField="ProductId" EnableAnimations="False" EnableDropDownAsChild="False"> <DropDownItemBinding TextField="Product" ValueField="ProductId" /> </EditorControl> </ig:DropDownProvider> <ig:DropDownProvider ID="ddpLOB"> <EditorControl DataSourceID="odsLOB" DropDownContainerMaxHeight="200px" TextField="Lob" ValueField="LobId" EnableAnimations="False" EnableDropDownAsChild="False"> <DropDownItemBinding TextField="Lob" ValueField="LobId" /> </EditorControl> </ig:DropDownProvider> </EditorProviders> </ig:WebHierarchicalDataGrid>
You could do a couple of things:
- Set property EnableDataViewState to true so that the new value is persisted during postback.
- Rebind the grid once you have updated the value in the database so that the new value is reflected.
It looks like even though you are updating your database correct, when the grid is rebinding, it is binding to the old set of data, thus not reflecting the new values.
-Taz.