GridView multirow edit client side validation
<p>I have a radgridview whcih contains template fields like the textbox's .
The radgrid is set with a property AllowMultiRowEdit="true" so i can edit multiple items at a time..I have added required field validators for each of these textboxes. with a unique validation group .This works fine only when i click on the update button (i.e validation) </p>

<p>On ItemDataBound i set attributes to these textboxes that is onkeypress attributes so that when the Enter key is pressed i perform an save..(Or Update)</p>

<p>How ever the problem here is if i use the key press from the textbox it validates the footer item insert row..!!!</p>

<p>Also the above control is wrapped within an update panel</p>

<p>Below is the simplified version of the code.</p>

<pre><code>&lt;RadGridID="_grid" OnItemDataBound="_grid_ItemDataBound"
                runat="server" AllowPaging="True" PageSize="10" AutoGenerateColumns="False" AllowMultiRowEdit="true"&gt;
                &lt;MasterTableView DataKeyNames="Id" CommandItemDisplay="None" ShowGroupFooter="true"
                    ShowFooter="true" AutoGenerateColumns="False" EditMode="InPlace" Width="100%"&gt;
                    &lt;Columns&gt;
&lt;telerik:GridTemplateColumn ItemStyle-Width="70px" UniqueName="units" HeaderText='&lt;%$ Resources: Labels, LIT_NUMBER %&gt;'&gt;
                            &lt;ItemTemplate&gt;
                                &lt;%#Eval("Units") %&gt;
                            &lt;/ItemTemplate&gt;
                            &lt;EditItemTemplate&gt;
                                &lt;telerik:RadNumericTextBox MinValue="0" Type="Number" NumberFormat-DecimalDigits="0"
                                    Width="20px" ID="_txtNumber" runat="server" DbValue='&lt;%#Bind("Units") %&gt;'&gt;
                                &lt;/telerik:RadNumericTextBox&gt;
                                &lt;asp:RequiredFieldValidator ToolTip='&lt;%$ Resources:Labels, TOOLTIP_REQUIRED%&gt;' ID="_rfvNumber"
                                    runat="server" ErrorMessage="*" SetFocusOnError="true" Display="Static" ControlToValidate="_txtNumber"&gt;&lt;/asp:RequiredFieldValidator&gt;
                            &lt;/EditItemTemplate&gt;
                        &lt;/telerik:GridTemplateColumn&gt;
                        &lt;telerik:GridTemplateColumn UniqueName="Unit" ItemStyle-Width="60px" HeaderText='&lt;%$ Resources: Labels, LIT_UNIT %&gt;'&gt;
                            &lt;ItemTemplate&gt;
                                &lt;%#Eval("Unit") %&gt;
                            &lt;/ItemTemplate&gt;
                            &lt;EditItemTemplate&gt;
                                &lt;telerik:RadTextBox ID="_txtUnit" runat="server" Text='&lt;%#Bind("Unit") %&gt;' Width="50%"&gt;
                                &lt;/telerik:RadTextBox&gt;
                                &lt;asp:RequiredFieldValidator ID="_rfvUnit" runat="server" ErrorMessage="*" SetFocusOnError="true"
                                    Display="Static" ToolTip='&lt;%$ Resources:Labels, TOOLTIP_REQUIRED%&gt;' ControlToValidate="_txtUnit"&gt;&lt;/asp:RequiredFieldValidator&gt;
                            &lt;/EditItemTemplate&gt;
                        &lt;/telerik:GridTemplateColumn&gt;
&lt;/Columns&gt;
&lt;/MasterTableView&gt;
&lt;telerik:RadGrid&gt;
</code></pre>

<p>OnLoad of the control i render the script </p>

<pre><code>function CheckEnter(currCon,e,controlId,validationGroup) {
                    var characterCode;
                    if (e &amp;&amp; e.which) {
                        e = e
                        characterCode = e.which
                    }
                    else {
                        e = event
                        characterCode = e.keyCode
                    }
                    if(characterCode==13)
                    {
                        if(Page_ClientValidate(validationGroup))
                        {
                            event.cancelBubble=true;
                            $get(controlId).click();
                        }
                        else
                        {
                            event.cancelBubble=true;
                        }
                        currCon.focus();
                    }
                    }
</code></pre>

<p>Also before the databind for the grid occurs i set the </p>

<pre><code>_gridProposalLines.MasterTableView.InsertItemDisplay = GridInsertItemDisplay.Bottom;
            _gridProposalLines.MasterTableView.IsItemInserted = true;
</code></pre>

<p>Here is the ItemDataBound event </p>

<pre><code>protected void _grid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            string clientID = "";
            RadNumericTextBox number = item.FindControl("_txtNumber") as RadNumericTextBox;
                RadTextBox unit = item.FindControl("_txtUnit") as RadTextBox;
             string randomNumber = "";
                ImageButton updateButton = item.FindControl("UpdateButton") as ImageButton;

                randomNumber = //Generate a random number  
              if (updateButton != null)
                {
                    updateButton.ValidationGroup = randomNumber;
                    clientID = updateButton.ClientID;
                }
                else
                {
                    ImageButton insertButton = (ImageButton)item.FindControl            ("PerformInsertButton");
                    insertButton.ValidationGroup = randomNumber;
                    clientID = insertButton.ClientID;
                }     
                               RequiredFieldValidator validatorNumber = item.FindControl("_rfvNumber") as RequiredFieldValidator;
                RequiredFieldValidator validatorUnit = item.FindControl("_rfvUnit") as RequiredFieldValidator;

                number.Attributes.Add("onkeypress", string.Format("CheckEnter(this,event,'{0}','{1}')", clientID, randomNumber));
                unit.Attributes.Add("onkeypress", string.Format("CheckEnter(this,event,'{0}','{1}')", clientID, randomNumber));


}
</code></pre>

<p>Thanks,
Francis P.</p>
