0
我有一個數據庫來自數據庫的列表框。但即使未選擇值,驗證也會通過。 我已經嘗試過,只是簡單的必需字段驗證程序,也不工作。 這是代碼。asp.net listbox驗證通過沒有選擇的值
<asp:Panel ID="panelDelivery" runat="server" Visible="false"
style="position: relative; top: -130px; background-color: #66FF33; left: 0px;" >
<asp:Label ID="lblOverWeight" runat="server" Width="344px"></asp:Label><br />
<asp:ListBox ID="listBxDelivery" runat="server" DataSourceID="Delivery"
DataTextField="DataText" DataValueField="Price" Width="489px"
AppendDataBoundItems="True" CausesValidation="True" AutoPostBack="True"
style="top: 0px; left: 0px">
</asp:ListBox>
<asp:RequiredFieldValidator ID="rfvDelivery" runat="server"
ErrorMessage="* Select Delivery " ControlToValidate="listBxDelivery"></asp:RequiredFieldValidator>
RequiredFieldValidator的例子,如果有在控制沒有數據纔有效。既然你正在談論從列表框中選擇你可能需要一個customValidator,然後在那裏執行檢查。 –