• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 79
  • Last Modified:

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
0
Ahelbling
Asked:
Ahelbling
  • 3
1 Solution
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now