代码之家  ›  专栏  ›  技术社区  ›  kbvishnu

ASP:DataList的验证

  •  0
  • kbvishnu  · 技术社区  · 16 年前

    我有一个ASP数据列表,如下所示。这里我有一个复选框,如果我单击了该复选框,我需要为相应的文本框输入一个数字。我如何验证它。如果我单击了一个复选框,我必须在文本框中输入一些值(int)。只需对点击的内容进行验证。提前谢谢!

     <asp:DataList ID="dlstEnergyItems" runat="server"
        RepeatColumns="4" RepeatDirection="Horizontal"  Width="100%">
        <ItemTemplate>
            <asp:CheckBox ID="cbEnergyItems" runat="server" />
            <asp:HiddenField ID="HdfEnergy" runat="server" />
            <asp:HiddenField ID="HdfEnergyCID" runat="server" />
            <asp:TextBox ID="txtBox" runat="server" />
        </ItemTemplate>
    </asp:DataList>
    
    3 回复  |  直到 12 年前
        1
  •  0
  •   Nithesh Narayanan    16 年前

    使用Ajax控件验证程序为每个复选框插入ASP文本框,并使其可见性和验证为假。在检查事件上使其可见并设置为真以进行验证。因此,通过使用AjaxControl验证器,您可以验证文本框…

        2
  •  0
  •   Bonshington    16 年前
    $("#dlstEnergyItems").find("input[type='checkbox']").change(function(){
     var checkbox = $(this);
     var tr = checkbox.closest("tr");
     var textbox = tr.find("input[type='text']");
    
     if(!checkbox.is(":selected")){ 
      textbox.unbind("blur");
      return;
     }
     else{
      textbox.focus();
      textbox.blur(function(){
       if(textbox.val().length == 0){
        alert("pls fill textbox");
        textbox.focus();
       }
      });
     }
    

    (});

        3
  •  0
  •   kbvishnu    16 年前

    这对我来说很好

     function chkEnergy() {
          var fails = $('.check:has(input:checked)').next("[value=0]").length;
          if (fails > 0) showStatus(true, "Please specify the Quantity");
          return fails === 0;
        }
    

    尼克·克雷弗

    推荐文章