本文介绍了必填字段验证器不适用于有限的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在与数据库绑定的下拉列表上应用验证
how to apply validation on dropdown list which is bounded with database
推荐答案
<asp:DropDownList ID="ddlSuggArea" runat="server" DataSourceID="sdsSuggArea" DataTextField="Area_Desc"
DataValueField="Area_Id" AppendDataBoundItems="True" CausesValidation="True">
<asp:ListItem Selected="True" Value="0">Choose Area...</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvSuggArea" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="ddlSuggArea" SetFocusOnError="True" InitialValue="0">Please choose a topic area</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator
ID="your_id"
runat="server"
ErrorMessage="Please Select Value"
ControlToValidate="your_dropdownlist"
InitialValue="-Select-"
Display="dynamic"
Enabled="false">
</asp:RequiredFieldValidator>
将数据源绑定到下拉列表后,将第一个选项插入为请选择".
在必填字段验证器中设置Intial值.
可以在下拉菜单中添加新值,如下所示:
Once you bind the datasource to the Dropdownlist, insert first option as "Please Select".
Set the Intial value in Required field validator.
New value can be added in dropdown as follows:
your_dropdownlist.Items.Insert(0, new ListItem("-Select-","-Select-");
这篇关于必填字段验证器不适用于有限的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!