Wednesday, 5 September 2012

Bind DropdownList without postback using javascript

 

Generally dropdownlist is the most useful control in our applications but in some cases it is difficult to get flexible binding. This type of binding done by javascript is more efficient and easy to handle.

This type of binding can get data from PageMethods (or) WebServices etc. By getting the data we can bind to dropdownlist through javascript.

JAVASCRIPT:

<script type="text/javascript">

        function pageLoad() {
            PageMethods.GetData(CallMethod);
        }

        function CallMethod(result) {
            var ddl = document.getElementById("ddl");
            for (D = 0; D < result.length; D++) {
                opt = new Option(result[D], result[D]);
                ddl.add(opt);
            }
        }

</script>

pageLoad function is just similar to PageLoad event is server side. In clientside pageLoad i am calling PageMethods and getting the data here. The obtained data is in the form of "List" and can be easily handled.

PAGEMETHODS:
[WebMethod(EnableSession=true)]
    public static List<string> GetData()
    {
        List<string> list = new List<string>();
        list.Add("one");
        list.Add("two");
        list.Add("three");
        list.Add("four");
        list.Add("five");
        return list;
    }

Here in this case i have done a sample list<string>. The final List will get returned to the javascript function.

Sample code will be obtained here Click Here

Related Posts:

  • Replace characters in javascript In server side we have "Replace" method to replace the characters in a string but on javascript replace method will be not useful in certain cases instead of that we can do for loop to replace the particular characters and g… Read More
  • Different Culture Names CULTURE ||SPEC.CULTURE||ENGLISH NAME af af-ZA Afrikaans af-ZA af-ZA Afrikaans (South Africa) ar ar-SA Arabic ar-AE ar-AE Arabic (U.A.E.) ar-BH ar-BH Arabic … Read More
  • Word document in iframe This is screen shot for iframe.Here In the below Screenshot iframe viewing the word document in the form of html. so i am giving html to the Iframe src. Iframe can view excel,csv,pdf,text file… Read More
  • Culture info in RadDateTime Picker In this example we can give culture info for localization in RadDatetimePicker. for this below example u can get different localizations according to their country. it is one of the property in RadDateTimePicke… Read More
  • Word Documents and Excel Documents in IFRAME In this below example we are converting word OR excel document to HTML. In this case we are converting and giving converted HTML file as ""src"" to ""iframe"". Step By Step Procedure : 1)First step is create one… Read More

1 comments:

  1. Sultan Casino Review | Honest Review by Shootercasino.com
    Read 제왕 카지노 our Sultan Casino review, find out why it's a great choice, 카지노사이트 and learn how to deposit and withdraw at this trusted online 바카라 사이트 casino.

    ReplyDelete