gpt4 book ai didi

c# - asp.net 中列表框的验证器

转载 作者:行者123 更新时间:2023-11-30 13:40:27 24 4
gpt4 key购买 nike

<asp:ListBox ID="lst_newGrpMembers" 
DataValueField="Name"
SelectionMode="Multiple"
Width="120px"
ToolTip="Press ctrl to select multiple users"
runat="server">
</asp:ListBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="lst_newGrpMembers"
ErrorMessage="Atleast one member required"
CssClass="Error"
Text="*Atleast one member required"
ValidationGroup="CreateGroupValidationGroup">
</asp:RequiredFieldValidator>

我有一个列表框的必填字段验证器,它验证并显示列表框中没有条目的错误,但是当我将项目添加到列表框时,它仍然显示错误。当我选择我添加的列表框项目并单击提交时,它工作正常。如何验证列表框。

最佳答案

RequiredFieldValidator 上,尝试将 InitialValue 设置为空字符串:

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"          
InitialValue=""
ControlToValidate="lst_newGrpMembers"
ErrorMessage="Atleast one member required"
CssClass="Error"
Text="*Atleast one member required"
ValidationGroup="CreateGroupValidationGroup">
</asp:RequiredFieldValidator>

关于c# - asp.net 中列表框的验证器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7851044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com