Databound Dropdown List and validation

Discussion in 'ASP .Net Web Controls' started by Ric Castagna, Jan 15, 2004.

  1. Ric Castagna

    Ric Castagna Guest

    Hello, all...

    I'm trying to do a client-side validation on a databound dropdown
    list.

    All I want to do is check to see if the selected index is greater than
    0 - an invalid option.

    Here's the code I'm using, but I don't think the compare validator is
    the right validation method to use. It, unfortunately, always thinks
    there's an error.

    <asp:dropdownlist id="ddlCategories" cssclass="adminText"
    datatextfield="cat_desc" datavaluefield="cat_id" runat="server" />
    <asp:comparevalidator id="cvCategories" operator="LessThan"
    controltovalidate="ddlCategories" valuetocompare="1"
    errormessage="Please select a category for this clip."
    display="Dynamic" runat="server" />

    I can't seem to find any postings on using validation against dropdown
    lists on the client side, and I'd prefer to keep the validation there
    as sending it server-side would really junk up the works.

    Please help.

    Thanks!
    Ric Castagna, Jan 15, 2004
    #1
    1. Advertising

  2. Ric Castagna

    Teemu Keiski Guest

    Hi,

    you can use RequiredFieldValidator for it, just set the InitialValue
    property to the value of the first item in the DDL (the invalid one) and it
    will then ensure that correct selection is made.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    "Ric Castagna" <> wrote in message
    news:...
    > Hello, all...
    >
    > I'm trying to do a client-side validation on a databound dropdown
    > list.
    >
    > All I want to do is check to see if the selected index is greater than
    > 0 - an invalid option.
    >
    > Here's the code I'm using, but I don't think the compare validator is
    > the right validation method to use. It, unfortunately, always thinks
    > there's an error.
    >
    > <asp:dropdownlist id="ddlCategories" cssclass="adminText"
    > datatextfield="cat_desc" datavaluefield="cat_id" runat="server" />
    > <asp:comparevalidator id="cvCategories" operator="LessThan"
    > controltovalidate="ddlCategories" valuetocompare="1"
    > errormessage="Please select a category for this clip."
    > display="Dynamic" runat="server" />
    >
    > I can't seem to find any postings on using validation against dropdown
    > lists on the client side, and I'd prefer to keep the validation there
    > as sending it server-side would really junk up the works.
    >
    > Please help.
    >
    > Thanks!
    Teemu Keiski, Jan 16, 2004
    #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. Simon Harvey
    Replies:
    2
    Views:
    400
    Christopher Reed
    Jan 18, 2006
  2. Lair
    Replies:
    2
    Views:
    640
    sloan
    Jun 21, 2006
  3. Steve
    Replies:
    3
    Views:
    460
    Karl Seguin [MVP]
    Sep 14, 2006
  4. rodchar
    Replies:
    0
    Views:
    379
    rodchar
    Nov 26, 2007
  5. Manu
    Replies:
    0
    Views:
    159
Loading...

Share This Page