DropDownLists

Discussion in 'ASP .Net' started by Mirnes, May 18, 2007.

  1. Mirnes

    Mirnes Guest

    Hi all!

    In one page I have 5 dropdown lists since I want to be able to add one
    company into max. 5 different categories but also to choose only one
    category, and there I came to the problem: I want those categories to
    be different. Ok, I used CompareValidator and it is not problem, but
    then I added new static item into every dropdown with value "-1" and
    text "Select category" and now I have problem because Validator finds
    that dropdown values are the same and blocks addition.

    The best solution for me is that I remove item which is selected in
    one dropdown list from other 4 dropdown lists or at list to make
    Validator not checks values < 0, but I don't know how to make any of
    these 2 solution.
    Mirnes, May 18, 2007
    #1
    1. Advertising

  2. On May 18, 4:50 pm, Mirnes <> wrote:
    > Hi all!
    >
    > In one page I have 5 dropdown lists since I want to be able to add one
    > company into max. 5 different categories but also to choose only one
    > category, and there I came to the problem: I want those categories to
    > be different. Ok, I used CompareValidator and it is not problem, but
    > then I added new static item into every dropdown with value "-1" and
    > text "Select category" and now I have problem because Validator finds
    > that dropdown values are the same and blocks addition.
    >
    > The best solution for me is that I remove item which is selected in
    > one dropdown list from other 4 dropdown lists or at list to make
    > Validator not checks values < 0, but I don't know how to make any of
    > these 2 solution.


    Well, I think you will need 5 CustomValidator Controls.

    Example

    <asp:CustomValidator Id="cv1"
    ControlToValidate="DropDownList1"
    Text="Category is not unique!"
    OnServerValidate="DropDownList1_ServerValidate"
    ClientValidationFunction="DropDownList1_ClientValidate"
    Runat="server" />

    <asp:DropDownList ID="DropDownList1" runat="server">
    <asp:ListItem Text="" Value=""></asp:ListItem>
    <asp:ListItem Text="1" Value="1"></asp:ListItem>
    <asp:ListItem Text="2" Value="2"></asp:ListItem>
    </asp:DropDownList>

    ....

    Here's a code of a client-side validation function with the first
    CustomValidator control.

    <script type="text/javascript">

    function DropDownList1_ClientValidate(source, args)
    {
    var DropDownList1 = document.getElementById("DropDownList1");
    var DropDownList2 = document.getElementById("DropDownList2");
    ....

    if (DropDownList1.selectedIndex == 0 || (DropDownList1.selectedIndex !
    = DropDownList2.selectedIndex ...))
    {
    args.IsValid = true;
    } else {
    args.IsValid = false;
    }
    }
    </script>

    function DropDownList2_ClientValidate(source, args)
    {
    ....
    }

    ....
    Alexey Smirnov, May 18, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter J. Hunter

    Positioning in dropdownlists

    Peter J. Hunter, Jan 14, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    517
    Peter J. Hunter
    Jan 14, 2004
  2. Craig Buchanan

    parent child dropdownlists acting oddly

    Craig Buchanan, Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    464
    Craig Buchanan
    Jun 27, 2003
  3. Darren

    Multiple DropDownLists

    Darren, Aug 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    408
    Steve C. Orr, MCSD
    Aug 18, 2003
  4. Colin Basterfield

    DropDownLists in XSLT

    Colin Basterfield, Dec 17, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    490
    Colin Basterfield
    Dec 17, 2003
  5. Craig Buchanan

    reuse SQLDataReader in multiple dropdownlists?

    Craig Buchanan, Jan 12, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    3,276
    Craig Buchanan
    Jan 15, 2004
Loading...

Share This Page