DropDownList框中的asp.net验证框 [英] asp.net Validation on DropDownList box

查看:171
本文介绍了DropDownList框中的asp.net验证框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表(cboViewAlbums),显示相册值。第一个项目是
请选择一个相册... 。我尝试使用验证,当lb_create_album linkBut​​ton被点击时,如果cboViewAlbums列表的值为0,则会抛出错误。
下面是这个和我的尝试的代码:

I have a dropdownlist (cboViewAlbums) which has displays album values. The first item is a Please select an album.... I am trying to use validation which when lb_create_album linkButton is clicked throws an error if the cboViewAlbums list has the value 0 selected. Below is the code for the this and my attempt:

<asp:DropDownList ID="cboViewAlbums" runat="server" 
         DataSourceID="SqlDataSource1" DataTextField="album_name" 
         DataValueField="album_id" Width="250px" AutoPostBack="True" AppendDataBoundItems="true">
         <asp:ListItem Value="0">Please select an album...</asp:ListItem>
         </asp:DropDownList>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <asp:LinkButton ID="lb_create_album" runat="server">Create Album</asp:LinkButton>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:fpaConnectionString %>"
        SelectCommand="SELECT [album_id], [album_name] FROM [fpa_albums] ORDER BY [album_name]">
    </asp:SqlDataSource>
     <br />
     <asp:HyperLink CssClass="example7" ID="hLinkUploadPhotos" NavigateUrl="multiple_upload.aspx" runat="server">Upload Multiple Photos</asp:HyperLink>
     <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
         ControlToValidate="cboViewAlbums" ErrorMessage="Please Select an Album" 
         InitialValue="Please select an album..."></asp:RequiredFieldValidator>

任何想法,我可以得到这个工作吗?

Any idea how I can get this working?

谢谢

推荐答案

您必须使用带有下拉列表的Range验证器&安培;将mininmum值设置为大于0&最大值设置任何最大值,aslo提供类型值min& max,这是整数

You have to use Range validator with dropdown list & set mininmum value greater then 0 & maximum value to set any max value , aslo provide type value of min & max and that is integer.

以下是我为您编写的示例代码,您必须绑定静态列表项的数据源。

Below is the sample code i have make for you you have to bind your datasource insted of static list items.

<asp:DropDownList runat="server" ID="ddl1" >
        <asp:ListItem Value="0" Text="Select value" />
        <asp:ListItem Value="1" Text="text1" />
        <asp:ListItem Value="2" Text="text2" />
    </asp:DropDownList>
    <asp:RangeValidator ErrorMessage="Please select value" ControlToValidate="ddl1" runat="server"
        MinimumValue="1" MaximumValue="100000000" Type=Integer />
    <asp:Button Text="text" runat="server"  />

如果对您有帮助,请标记为答案

If this helpful to you please mark as an answer

谢谢

Arun

这篇关于DropDownList框中的asp.net验证框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆