Mohd Malaka Weblog

About anything….

  • Welcome


    Welcome to my Weblog. Here I post about anything, mainly about programming. Enjoy

  • Archives

  • Flickr Photos

    Dublin

    Dublin



    Garda

    Twins

    More Photos
  •  

    May 2009
    M T W T F S S
    « Mar   Jul »
     123
    45678910
    11121314151617
    18192021222324
    25262728293031
  • free counters

Archive for May, 2009

C#: Bind a DropDownList to IDictionary using AjaxPro

Posted by malakablog on May 1, 2009

- Implement an AjaxMethod to return IDictionary object

 

[AjaxPro.AjaxMethod]

public IDictionary AjaxGetIDictionary()

{

//Prepare the IDictionary object

}

- Use JavaScript to request the AjaxMethod AjaxGetIDictionary

MyAjaxClass. AjaxGetIDictionary (jsAjaxGetIDictionary_Callback);

- In the JavaScript function jsAjaxGetIDictionary_Callback add the IDictionary items to the DopDownList

function jsAjaxGetIDictionary (response)

{

     try

    {

         var DictionaryItems= response.value;

         if (DictionaryItems == null || typeof(DictionaryItems) != “object”)

        {

               return;

         }

         var myDropDownList = document.getElementById(“myDropDownList”);

         myDropDownList.options.length = 0;

         for (var i = 0; i < response.value.length; ++i)

         {

             myDropDownList.options[myDropDownList.options.length] = new Option(response.value[i].Value,response.value[i].Key);

           }

    }

    catch(e)

   {

   }

}

Posted in Uncategorized | Tagged: , , , , , , , , , | Leave a Comment »