• 彻底解决DropDownList验证问题,支持后台读取数据库!


    微软提供的RequiredFieldValidator对于TextBox之类前台验证确实很好用,但遇到DropDownList验证就黔驴技穷了,呵呵,其实不然,听我细细道来:

    刚开始遇到这种情况,采用纯后台验证或者纯前台验证的方式,发现都差强人意,今天抽了一个小时把它啃下了!

    实现了前台既能使用RequiredFieldValidator 验证DropDownList ,后台又能读数据库,呵呵!

    相关代码

    aspx:

    <asp:DropDownList ID="ddlService" runat="server" CssClass="ddls" AppendDataBoundItems="true">
                                <asp:ListItem Selected="True">--请选择--</asp:ListItem>
                                </asp:DropDownList>
     
    <asp:RequiredFieldValidator ID="re" runat="server" ControlToValidate="ddlService"
                                    ErrorMessage="请选择一项" InitialValue="--请选择--"></asp:RequiredFieldValidator>

    aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                  ddlService.DataSource = prtBll.GetService();
              ddlService.DataTextField = "SERVICE_NAME";
                  ddlService.DataValueField = "SERVICE_CODE";
                  ddlService.DataBind();       

            }
        }       

    朋友们,你们是否也遇到同样问题,是否苦恼过,看看这些资料对你有用吗?

           

  • 相关阅读:
    Game Engine Architecture 3
    Game Engine Architecture 2
    补码
    工厂模式
    Game Engine Architecture 1
    YDWE Keynote
    3D Math Keynote 4
    3D Math Keynote 3
    3D Math Keynote 2
    OGRE中Any 类型的实现
  • 原文地址:https://www.cnblogs.com/Golf9527/p/1640262.html
Copyright © 2020-2023  润新知