如何解决requiredfieldvalidator 在 gridview onrowediting 中启用/禁用基于 radiobuttonlist 值
我有一个名为 GridViewMA 的网格视图。在 GridViewMA 的每一行上,我都有一个名为 rbAdj_Entry 的单选按钮列表控件。我目前在网格中有 5 个 requiredvalidator 字段。如果用户在单选按钮列表中选择一个值,我想启用所有 5 个 requiredvalidators。如果用户选择另一个值,我只想启用 2 个 requiredvalidators。因此,当他们单击要编辑的命令按钮时,就是我希望代码检查单选按钮列表并应用验证器的时间。当他们按下页脚行中的添加按钮时,同样的事情。
<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,ibs,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,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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。