Missing Pending Changes on ChildRow

2 replies. Last post: August 6, 2010 10:41 AM by Guillermo Montes
Tags :
  • New Discussion
  • New Question
  • New Product Feedback

Hi,

I'm trying to modify some records on a childrow from the parentrow in a hierarchical grid with batch update (as reference, I'm using part of the answer for some another reply I got in this thread ).

Problem is, when I'm picking the BatchUpdate event not all the changes are showing up on the BatchUpdateEventArgs.PendingChanges collection, only the changes on the parent rows are there. I'm clicking the rowchecker on the parent row and that's supposed to trigger some changes on both the parent and its children. I think this might be an issue with the code I'm using to "commit the change" on the rows.

This is in my javascript event:

function webGrid_CheckBoxClick(gridId, tblName, colName, checkboxValue, originalCheckBoxValue) {
        var grid = ISGetObject(gridId);
        var row = grid.Tables[tblName].ToRowObject(grid.CheckedRowContext);
        if (colName == 'Checker') {
            var newCountryName = row.GetCell('CountryName').Text + "_New";
            row.GetCell('CountryName').SetValue(newCountryName);
            row.GetCell('CountryName').SetText(newCountryName);
            row.GetCell('Active').CellElement.childNodes[0].click();            
            
            //Expand child
            if (!row.ChildExpanded) {
                row.ExpandChildRow(true);
            }
            //If no childs return
            var childRows = row.GetChildRows("Capital");
            if (childRows == null) {
                return;
            }
            //Check all childs and retrigger function
            for (var i = 0; i < childRows.length; i++) {
                childRows[i].Check();
            }
            row.SetDataChanged();
            row.AcceptChanges();
            grid.MarkEdit();
        }
        else if (colName == 'CapitalChecker') {
            var newCapitalName = row.GetCell('CapitalName').Text + "_New";
            row.GetCell('CapitalName').SetValue(newCapitalName);
            row.GetCell('CapitalName').SetText(newCapitalName);
            row.GetCell('CapitalActive').CellElement.childNodes[0].click();
            row.SetDataChanged();
            row.AcceptChanges();
            grid.MarkEdit();
        }
    }

 

And this is my grid definition:

<ISNet:WebGrid ID="webGrid" runat="server" UseDefaultStyle="true" OnInitializeDataSource="webGrid_IDS" OnBatchUpdate="webGrid_BU">
        <RootTable DataMember="Country" DataKeyField="CountryID">
            <Columns>
                <ISNet:WebGridColumn ColumnType="CheckBox" IsRowChecker="true" Name="Checker" Bound="false" />
                <ISNet:WebGridColumn DataMember="CountryID" Name="CountryID" />
                <ISNet:WebGridColumn DataMember="CountryName" Name="CountryName" />
                <ISNet:WebGridColumn DataMember="Active" Name="Active" />
            </Columns>
            <ChildTables>
                <ISNet:WebGridTable DataMember="Capital" DataKeyField="CapitalID" >
                    <Columns>
                        <ISNet:WebGridColumn ColumnType="CheckBox" IsRowChecker="true" Name="CapitalChecker" Bound="false" />
                        <ISNet:WebGridColumn DataMember="CapitalID" Name="CapitalID" />
                        <ISNet:WebGridColumn DataMember="CapitalName" Name="CapitalName" />
                        <ISNet:WebGridColumn DataMember="Active" Name="CapitalActive" />
                    </Columns>
                </ISNet:WebGridTable>
            </ChildTables>
        </RootTable>
        <LayoutSettings AllowBatchUpdate="true" AllowEdit="Yes" Hierarchical="true">
            <ClientSideEvents OnCheckBoxClick="webGrid_CheckBoxClick"/>
            <BatchUpdateSettings PromptUnsavedChanges="false" />
        </LayoutSettings>
    </ISNet:WebGrid>

 

And this is in my code behind:

protected void webGrid_IDS(object sender, DataSourceEventArgs e)
        {
            e.DataSource = GetDataSet();
        }
        protected void webGrid_BU(object sender, BatchUpdateEventArgs e)
        {
            var changeCount = e.PendingChanges.Count;
            var changeCollection = e.PendingChanges;
            foreach (var change in changeCollection)
            { 
            } 
        }
        protected void btnBatchUpdate_Click(object sender, EventArgs e)
        {
            webGrid.PerformBatchUpdate(false);
        }
        private DataSet GetDataSet()
        {
            DataSet test = new DataSet();
            DataTable country = test.Tables.Add("Country");
            DataTable capital = test.Tables.Add("Capital");
            country.Columns.Add("CountryID", typeof(int));
            country.Columns.Add("CountryName", typeof(string));
            country.Columns.Add("Active", typeof(bool));
            capital.Columns.Add("CapitalID", typeof(int));
            capital.Columns.Add("CountryID", typeof(int));
            capital.Columns.Add("CapitalName", typeof(string));
            capital.Columns.Add("Active", typeof(bool));
            country.Rows.Add(1, "France", false);
            country.Rows.Add(2, "Spain", false);
            capital.Rows.Add(10, 1, "Paris", false);
            capital.Rows.Add(20, 2, "Madrid", false);
            test.Relations.Add(new DataRelation("CountryCapital", country.Columns[0], capital.Columns[1]));
            return test;
        }

 


Thanks for any feedback on this


All times are GMT -5. The time now is 9:34 AM.
Previous Next