Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1410
how to retrieve value from webdropdown field
posted

Hi,

I am using webdropdown version: 11.2.20112.1019. I would like to retrieve value and lenght of the dropdown item(s) based upon ID and do some valildations in javascript. Can you tell me the syntax of retrieving value and length from this dropdown field.

 

Parents
No Data
Reply
  • 3115
    Suggested Answer
    Offline posted

    Hi SunilMehta,

    I was not sure if you need the length of the items collection, or the length of the current item (as a number of the characters it contains), so I've provided both samples.

    Here is code that take an instance of the WebDropDown, by ID. Keep in mind that if you use master pages and your control is in content place holder its id get changed when rendered, so you need to use a debugger to find its id and pass it as an argument to the find function. If you are using ASP.NET 4 you can also set ClientIDMode="Static", which won't change the value of the id.

       19         function clickHandler() {

       20             //Get instance of the webdropdown

       21             var dd = $find("WebDropDown1");

       22             //Get the length of the items collection

       23             var length = dd.get_items().getLength();

       24             //Get item with index 0

       25             var item = dd.get_items().getItem(0);

       26             //Get the text of the item

       27             var textValue = item.get_text();

       28             //Get the string length

       29             var stringLength = textValue.length;

       30         }

     

    Hope that helps,

    Thanks

Children