asp.net radGrid batch update validation?

Having issues figuring out why the batch edit validation is only appearing to work for every other row in my radGrid.  I believe it may be some sort of styling issue as PostBack does not occur until all rows/cells are populated...
Ideas?

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    
    <style type="text/css">
        .failedValidation {
            background: #BC5858!important;
        }
    </style>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    
    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function gridCommand(sender, args) {
                if (args.get_commandName() == "BatchEdit") {
                    var validationFails = false;
                    var masterTable = sender.get_masterTableView();
                    var batchManager = sender.get_batchEditingManager();
                    var dataItems = masterTable.get_dataItems();

                    for (var i = 0; i < dataItems.length; i++) {
                        var Cell1 = dataItems[i].get_cell("SampleNum"); //get reference to the cells you want to validate
                        var id1 = batchManager.getCellValue(Cell1); //retrieve the value from the cell using the BatchEditingManager
                        var Cell2 = dataItems[i].get_cell("TranLineNum"); //get reference to the cells you want to validate
                        var id2 = batchManager.getCellValue(Cell2); //retrieve the value from the cell using the BatchEditingManager 

                        /// custom validation 							
                        ///
                        dataItems[i].get_element().className = dataItems[i].get_element().className.replace(" failedValidation", "");

                        if (id1 < 1 || id2 < 1) {
                            dataItems[i].get_element().className += " failedValidation";
                            validationFails = true;
                        }
                        else {
                            dataItems[i].get_element().className = dataItems[i].get_element().className.replace(" failedValidation", "");
                        }
                        ///
                        /// end of custom validation
                    }

                    if (validationFails) {
                        args.set_cancel(true);
                    }
                }
            }
        </script>
    </telerik:RadCodeBlock>

        <asp:Panel ID="pnlForm" runat="server">
            <telerik:RadGrid ID="rgSearch" runat="server" RenderMode="Auto" AutoGenerateColumns="False" CellSpacing="1" AllowSorting="False" width="50%" Visible="True" 
                OnItemUpdated="rgSearch_ItemUpdated"  AllowAutomaticUpdates="True" AllowAutomaticInserts="False">
                <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
                <ClientSettings  EnableRowHoverStyle="True" Selecting-AllowRowSelect="false" EnablePostBackOnRowClick="false">
                    <Scrolling AllowScroll="False" UseStaticHeaders="True" />
                    <ClientEvents OnCommand="gridCommand" />
                </ClientSettings>
                <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="CID" EditMode="Batch" CommandItemDisplay="TopAndBottom">
                    <CommandItemSettings ShowSaveChangesButton="true" />
                    <CommandItemSettings ShowCancelChangesButton="true" />
                    <CommandItemSettings  ShowAddNewRecordButton="false"  />
                    <CommandItemSettings SaveChangesText="SAVE" />
                    <BatchEditingSettings EditType="Row" />
                    <SortExpressions>
                    <telerik:GridSortExpression FieldName="CID" SortOrder="Descending" />
                    </SortExpressions>
                    <Columns>
                        <telerik:GridBoundColumn DataField="CID" HeaderText="Barcode" SortExpression="CID" UniqueName="CID" HeaderStyle-Width="125px" ReadOnly="True">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="LabelName" HeaderText="LabelName" UniqueName="LabelName" HeaderStyle-Width="200px" ReadOnly="True">                                  
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="SampleNum" HeaderText="SampleNumber" UniqueName="SampleNum" HeaderStyle-Width="165px">                                  
                           <%-- <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ForeColor="Red" Text="*Required" Display="Dynamic">
                                </RequiredFieldValidator>
                            </ColumnValidationSettings>--%>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TranLineNum" HeaderText="TransLineNumber" UniqueName="TranLineNum" HeaderStyle-Width="165px">                                  
                           <%-- <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ForeColor="Red" Text="*Required" Display="Dynamic">
                                </RequiredFieldValidator>
                            </ColumnValidationSettings>--%>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="CreatedBy" HeaderText="Created By" UniqueName="CreatedBy" HeaderStyle-Width="150px" ReadOnly="True">                                  
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn HeaderText="">
                        <ItemTemplate>
                            &nbsp;
                        </ItemTemplate>
                        <EditItemTemplate>
                            &nbsp;
                        </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
                <FilterMenu RenderMode="Lightweight"></FilterMenu>
                <HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
            </telerik:RadGrid>
        </asp:Panel>

Open in new window


ss1ss2ss3
AhelblingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AhelblingAuthor Commented:
ss4
0
AhelblingAuthor Commented:
is this a row vs altrow styling issue?
0
AhelblingAuthor Commented:
Found a solution that seems to work.

<ClientSettings EnableAlternatingItems="false">
</ClientSettings>

https://www.telerik.com/forums/removing-alternative-row-color-in-radgrid
0
leakim971PluritechnicianCommented:
Let's delay this with 10s to be sure, replace :
            function gridCommand(sender, args) {
                if (args.get_commandName() == "BatchEdit") {
                    var validationFails = false;
                    var masterTable = sender.get_masterTableView();
                    var batchManager = sender.get_batchEditingManager();
                    var dataItems = masterTable.get_dataItems();

                    for (var i = 0; i < dataItems.length; i++) {
                        var Cell1 = dataItems[i].get_cell("SampleNum"); //get reference to the cells you want to validate
                        var id1 = batchManager.getCellValue(Cell1); //retrieve the value from the cell using the BatchEditingManager
                        var Cell2 = dataItems[i].get_cell("TranLineNum"); //get reference to the cells you want to validate
                        var id2 = batchManager.getCellValue(Cell2); //retrieve the value from the cell using the BatchEditingManager 

                        /// custom validation 							
                        ///
                        dataItems[i].get_element().className = dataItems[i].get_element().className.replace(" failedValidation", "");

                        if (id1 < 1 || id2 < 1) {
                            dataItems[i].get_element().className += " failedValidation";
                            validationFails = true;
                        }
                        else {
                            dataItems[i].get_element().className = dataItems[i].get_element().className.replace(" failedValidation", "");
                        }
                        ///
                        /// end of custom validation
                    }

                    if (validationFails) {
                        args.set_cancel(true);
                    }
                }
            }

Open in new window

by :
function gridCommand(sender, args) {
      var sender = sender;
      var args = args;
      setTimeout(function() {                
           if (args.get_commandName() == "BatchEdit") {
                    var validationFails = false;
                    var masterTable = sender.get_masterTableView();
                    var batchManager = sender.get_batchEditingManager();
                    var dataItems = masterTable.get_dataItems();

                    for (var i = 0; i < dataItems.length; i++) {
                        var Cell1 = dataItems[i].get_cell("SampleNum"); //get reference to the cells you want to validate
                        var id1 = batchManager.getCellValue(Cell1); //retrieve the value from the cell using the BatchEditingManager
                        var Cell2 = dataItems[i].get_cell("TranLineNum"); //get reference to the cells you want to validate
                        var id2 = batchManager.getCellValue(Cell2); //retrieve the value from the cell using the BatchEditingManager 

                        /// custom validation 							
                        ///
                        dataItems[i].get_element().className = dataItems[i].get_element().className.replace(" failedValidation", "");

                        if (id1 < 1 || id2 < 1) {
                            dataItems[i].get_element().className += " failedValidation";
                            validationFails = true;
                        }
                        else {
                            dataItems[i].get_element().className = dataItems[i].get_element().className.replace(" failedValidation", "");
                        }
                        ///
                        /// end of custom validation
                    }

                    if (validationFails) {
                        args.set_cancel(true);
                    }
                }
            },10 * 1000); // 10 seconds delay TO BE SURE, TO REDUCE THE DELAY BEFORE BEING SURE
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.