Click here to Skip to main content
15,042,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview named GridViewMA. On each row of GridViewMA, I have a radiobuttonlist control named rbAdj_Entry. I currently have 5 requiredvalidator fields in the grid. if the user selects one value in the radiobuttonlist, I want to enable all 5 requiredvalidators. If the user selects the other value, I want to only enable 2 requiredvalidators. So when they click the CommandButton to Edit, is when I want the code to inspect the radiobuttonlist and apply the validators. Same thing when they press the Add button in the Footer row.

<asp:GridView ID="GridViewMA" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="dsManualAdjustments" CssClass = "grid"
        Height="100%" Width="100%"
        ShowFooter="True"
        DataKeyNames="REF_ID"
        OnSelectedIndexChanged="SelectedIndexChanged"
        OnRowEditing="OnRowEditing"
        OnRowCancelingEdit="OnRowCanceling"
        OnRowUpdating="OnRowUpdating"
        DataBindingComplete="DataBindingComp"
       OnRowDataBound="OnRowDataBound"
        AllowPaging="True"
        PageSize="17"
        EnableDelete="true">
        <AlternatingRowStyle BackColor="#cccccc" />
  <%--                              <HeaderStyle CssClass="GVFixedHeader" />
                <FooterStyle CssClass="GVFixedFooter" />--%>
        <Columns>

            <asp:CommandField ShowEditButton="True" 

            ButtonType="Link" 
            EditText="<img src='Images/edit2.png' border=0 title='Edit the Row'>"  
            UpdateText="<img src='Images/update2.png' border=0 title='Update the Row'>"
            CancelText="<img src='Images/cancel2.png' border=0 title='Cancel your changes'>">
        </asp:CommandField>

   <%--       <asp:TemplateField ShowHeader="false">
              <ItemTemplate>
                            <asp:imagebutton ID="LinkButton1" runat="server" CommandName="Edit" imageurl="~/Images/edit2.png" ToolTip='Edit the Row' Enabled="true"></asp:imagebutton>
              </ItemTemplate>
              <ItemStyle Width="25px" />
            </asp:TemplateField>--%>

            <asp:TemplateField ShowHeader="false">
              <ItemTemplate>
                            <asp:imagebutton ID="LinkButton2" runat="server" CommandName="Delete" imageurl="~/Images/delete2.png" OnClientClick="return confirm('Delete this entry?');"  ToolTip='Delete the Row' Enabled="true"></asp:imagebutton>
              </ItemTemplate>
              <ItemStyle Width="25px" />
            </asp:TemplateField>

          <asp:TemplateField ShowHeader="false">
              <ItemTemplate>
                            <asp:imagebutton ID="LinkButton3" runat="server" CommandName="Copy" imageurl="~/Images/copy2.png" 
                    OnClick="CopyRow" 
                    ToolTip='Copy the Row'  ></asp:imagebutton>
              </ItemTemplate>
              <ItemStyle Width="25px" />
              </asp:TemplateField>

            <asp:TemplateField HeaderText="Action" ItemStyle-Width="25px">
              <ItemTemplate>
             </ItemTemplate>

             <FooterStyle HorizontalAlign="Left" />
            <FooterTemplate>
                  <asp:Button ID="ButtonAdd" runat="server" Text="Add" OnClick="FirstGridViewRow" />
                    <asp:Button ID="ButtonUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" /> 
            </FooterTemplate>
            <ItemStyle HorizontalAlign="Left" Width="25px" />
            </asp:TemplateField>

              <asp:TemplateField HeaderText="Adj_Entry" ItemStyle-Width="25px">
              <ItemTemplate>
            
                     <asp:RadioButtonList ID="rbAdj_Entry" runat="server" >  
                                            <asp:ListItem Text="Adjust" Value="0" ></asp:ListItem>  
                                            <asp:ListItem Text="Entry" Value="1"></asp:ListItem>  
                                        </asp:RadioButtonList>  
             </ItemTemplate>
        <ItemStyle HorizontalAlign="Center" Width="125px" />
            <FooterStyle HorizontalAlign="Right"  BackColor="Blue"/>
            <FooterTemplate>
                    <asp:RadioButtonList ID="rbAdj_Entry" runat="server"  >  
                                            <asp:ListItem Text="Adjust" Value="0" Selected="True"></asp:ListItem>  
                                            <asp:ListItem Text="Entry" Value="1"></asp:ListItem>  
                                        </asp:RadioButtonList>  
            </FooterTemplate>
             </asp:TemplateField>

              <asp:TemplateField HeaderText="Comment" ItemStyle-Width="250px" SortExpression="Comment">
              <ItemTemplate>
                  <asp:label ID="lbl_Comment" runat="server" Text='<%# Eval("Comment") %>' width="250px"></asp:label>
              </ItemTemplate>
              <EditItemTemplate>
                  <asp:textbox ID="Comment" runat="server" Text='<%# Bind("Comment")%>' Visible="true" ReadOnly="false" Width="250px" MaxLength="50"></asp:textbox>
                  <asp:RequiredFieldValidator id="CommentValidator" ControlToValidate="Comment" Display="Static" ErrorMessage="Comment is required." ForeColor="Red" runat="server"/> 
              </EditItemTemplate>
               <FooterStyle HorizontalAlign="Right"  BackColor="Blue"/>
            <FooterTemplate>
                  <asp:Textbox ID="txtComment" runat="server" Text='<%# Eval("Comment") %>' width="250px" MaxLength="50"/>
                  <asp:RequiredFieldValidator id="CommentValidatorF" ControlToValidate="txtComment" Display="Static" ErrorMessage="Comment is required." ForeColor="Red" runat="server"/> 
            </FooterTemplate>
              <ItemStyle HorizontalAlign="Left" Width="300px" />
            </asp:TemplateField>         

            <asp:BoundField DataField="User_Id" HeaderText="User_Id" ReadOnly="True" SortExpression="User_Id" ItemStyle-Width="500" />
  

            <asp:BoundField DataField="Modified" HeaderText="Modified" ReadOnly="True" SortExpression="Modified"  ItemStyle-Width="400"/>
 
          <asp:BoundField DataField="Ref_Id" HeaderText="Ref_Id" ReadOnly="True" SortExpression="Ref_Id" />

 

             <asp:TemplateField HeaderText="Effective_Date" ItemStyle-Width="100px" SortExpression="Effective_Date" >
                  <ItemTemplate>
                  <asp:label ID="EffectiveDate" runat="server" Text='<%# Eval("Effective_Date", "{0:MM/dd/yyyy}") %>' width="100px" ></asp:label>
              </ItemTemplate>
              <EditItemTemplate >
                  <asp:textbox ID="txt_EffectiveDate" runat="server" CssClass="date" Text='<%# Bind("Effective_Date")%>' Visible="true" ReadOnly="false" Width="100px" ClientIDMode="AutoID" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="false"></asp:textbox>
                  <asp:RequiredFieldValidator id="EffectiveDateValidator" ControlToValidate="txt_EffectiveDate" Display="Static" ErrorMessage="Effective Date is required." runat="server" ForeColor="Red"/> 
               </EditItemTemplate>
               <FooterStyle HorizontalAlign="Right"  BackColor="Blue"/>
            <FooterTemplate>
                  <asp:Textbox ID="txtEffectiveDate" runat="server" Text='<%# Eval("Effective_Date", "{0:MM/dd/yyyy}") %>' width="100px" MaxLength="50" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="false"/>
                  <asp:RequiredFieldValidator id="EffectiveDateValidatorF" ControlToValidate="txtEffectiveDate" Display="Static" ErrorMessage="Effective Date is required." runat="server" ForeColor="Red"/> 
            </FooterTemplate>
              <ItemStyle HorizontalAlign="Left" Width="150px" />
            </asp:TemplateField>         

                        <asp:TemplateField HeaderText="Expiration_Date" ItemStyle-Width="100px" SortExpression="Expiration_Date">
                  <ItemTemplate>
                  <asp:label ID="ExpirationDate" runat="server" Text='<%# Eval("Expiration_Date", "{0:MM/dd/yyyy}") %>' width="100px"></asp:label>
              </ItemTemplate>
              <EditItemTemplate>
                  <asp:textbox ID="txt_ExpirationDate" runat="server" Text='<%# Bind("Expiration_Date")%>' Visible="true" ReadOnly="false" Width="100px" MaxLength="10"></asp:textbox>
              </EditItemTemplate>
               <FooterStyle HorizontalAlign="Right"  BackColor="Blue"/>
            <FooterTemplate>
                  <asp:Textbox ID="txtExpirationDate" runat="server" Text='<%# Eval("Expiration_Date", "{0:MM/dd/yyyy}") %>' width="100px" MaxLength="50"/>
            </FooterTemplate>
              <ItemStyle HorizontalAlign="Left" Width="150px" />
            </asp:TemplateField>    
            
 <%--     /* <asp:BoundField DataField="Asset_System_ID" HeaderText="Asset_System_ID" ReadOnly="True" SortExpression="Asset_System_ID" />--%>
                         <asp:TemplateField HeaderText="Asset System ID" ItemStyle-Width="100px" SortExpression="Asset_System_ID">
                  <ItemTemplate>
                  <asp:label ID="AssetSystemID" runat="server" Text='<%# Eval("Asset_System_ID") %>' width="100px"></asp:label>
              </ItemTemplate>
              <EditItemTemplate>
                  <asp:textbox ID="AssetSystemID" runat="server" Text='<%# Bind("Asset_System_ID")%>' Visible="true" ReadOnly="false" Width="150px" MaxLength="6"></asp:textbox>
              </EditItemTemplate>
               <FooterStyle HorizontalAlign="Right"  BackColor="Blue"/>
            <FooterTemplate>
                  <asp:Textbox ID="txtAssetSystemID" runat="server" Text='<%# Eval("Asset_System_ID") %>' width="100px" MaxLength="6"/>
            </FooterTemplate>
              <ItemStyle HorizontalAlign="Left" Width="100px" />
            </asp:TemplateField>         

                <asp:TemplateField HeaderText="System" ItemStyle-Width="100px" SortExpression="Asset_System_Mnemonic">
                  <ItemTemplate>
                  <asp:label ID="lblAssetSystemMnemonic" runat="server" Text='<%# Eval("Asset_System_Mnemonic") %>' width="100px"></asp:label>
 
              </ItemTemplate>
              <EditItemTemplate>
                  <asp:textbox ID="AssetSystemMnemonic" runat="server" Text='<%# Bind("Asset_System_Mnemonic")%>' Visible="true" ReadOnly="false" Width="150px" MaxLength="6"></asp:textbox>
                  <asp:RegularExpressionValidator ID="AssetSystemMnemonicValidator" runat="server" ControlToValidate="AssetSystemMnemonic" ErrorMessage="Enter ACBS,HAWK,IBS,IL,LM" ValidationExpression="^[acbs,ACBS,hawk,HAWK,ibs,IBS,il,IL,lm,LM]+$"  ForeColor="Red" ></asp:RegularExpressionValidator>/>
                  <asp:RequiredFieldValidator id="AssetSystemMnemonicValidatorR" ControlToValidate="AssetSystemMnemonic" Display="Static" ErrorMessage="System is required." runat="server" ForeColor="Red"/> 
              </EditItemTemplate>
               <FooterStyle HorizontalAlign="Right"  BackColor="Blue"/>
            <FooterTemplate>
                  <asp:Textbox ID="txtAssetSystemMnemonic" runat="server" Text='<%# Eval("Asset_System_Mnemonic") %>' width="100px" MaxLength="6"/>
                  <asp:RegularExpressionValidator ID="AssetSystemMnemonicValidatorF" runat="server" ControlToValidate="txtAssetSystemMnemonic" ErrorMessage="Enter ACBS,HAWK,IBS,IL,LM" ValidationExpression="^[acbs,ACBS,hawk,HAWK,ibs,IBS,il,IL,lm,LM]+$"  ForeColor="Red" ></asp:RegularExpressionValidator>/>
                  <asp:RequiredFieldValidator id="AssetSystemMnemonicValidatorRF" ControlToValidate="txtAssetSystemMnemonic" Display="Static" ErrorMessage="System is required." runat="server" ForeColor="Red"/> 
            </FooterTemplate>
              <ItemStyle HorizontalAlign="Left" Width="100px" />
            </asp:TemplateField> 
           
 

            <asp:TemplateField HeaderText="Loan_Number" ItemStyle-Width="200px" SortExpression="Loan_Number">
                  <ItemTemplate>
                  <asp:label ID="lblLoan_Number" runat="server" Text='<%# Eval("Loan_Number") %>' width="200px"></asp:label>
              </ItemTemplate>
              <EditItemTemplate>
                  <asp:textbox ID="Loan_Number" runat="server" Text='<%# Bind("Loan_Number")%>' Visible="true" ReadOnly="false" Width="200px" MaxLength="25"></asp:textbox>
                  <asp:RequiredFieldValidator id="LoanNumberValidator" ControlToValidate="Loan_Number" Display="Static" ErrorMessage="Loan Number is required."  ForeColor="Red"  runat="server"/> 
              </EditItemTemplate>
               <FooterStyle HorizontalAlign="Right"  BackColor="Blue"/>
            <FooterTemplate>
                  <asp:Textbox ID="txtLoanNumber" runat="server" Text='<%# Eval("Loan_Number") %>' width="200px" MaxLength="25"/>
                  <asp:RequiredFieldValidator id="LoanNumberValidatorF" ControlToValidate="txtLoanNumber" Display="Static" ErrorMessage="Loan Number is required."  ForeColor="Red"  runat="server"/> 
            </FooterTemplate>
              <ItemStyle HorizontalAlign="Left" Width="200px" />
            </asp:TemplateField>         


What I have tried:

I'm hoping I can enable/disable the RequiredFieldValidators and RegularExpressionValidators in the OnRowEditing method. Just don't know the syntax to check the RadioButtonList value and do the conditional enable/disable.

Please help!
Posted
Updated 8-Jun-21 11:40am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900