Esempio AJAX: caricamento di una dropdown da un datatable

Semplice esempio in Vb.net (referenziando la dll di AJAX per .NET) che consente, lato client, di invocare, tramite AJAX, un metodo che restituisce un datatable e caricare con

esso una dropdown.

funzione lato server che ritorna una datatable:

<Ajax.AjaxMethod()> _
      Public Function GetCountry() As DataTable
        Dim dt As New DataTable
        Dim i As Int16

        With dt
            .Columns.Add(New DataColumn("codice"))
            .Columns.Add(New DataColumn("descrizione"))
        End With

        For i = 0 To 50
            Dim r = dt.NewRow

            With r
                .item("codice") = i
                .item("descrizione") = "des_" & i.ToString
            End With

            dt.Rows.Add(r)

        Next

        Return dt

    End Function

Ricordarsi di mettere nel Load della pagina

Ajax.Utility.RegisterTypeForAjax(GetType(testAJAX))

 

Codice HTML

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="testAJAX.aspx.vb" Inherits="TEST.testAJAX"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <title>testAJAX</title>
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <input onclick="Fill();" type="button" value="Carica Lista">
   <span id="dd" name="dd"></span>
  </form>
  <script language="javascript">
  
   function Fill()
   {
     var html = [];
     
     
     for(var i=0; i<testAJAX.GetCountry().value.Rows.length; i++)
      {
      v = testAJAX.GetCountry().value.Rows[i].codice
      t = testAJAX.GetCountry().value.Rows[i].descrizione
      html[html.length] = "<option value=\" + v + \">" + t + "</option>";
      }
     
     document.getElementById("dd").innerHTML = "<select id=\"sel\">" + html.join("") + "</select>";
   }
   

  </script>
 </body>
</HTML>

 

 

posted @ martedì 30 agosto 2005 20:42

Print

Comments on this entry:

# re: Esempio AJAX: caricamento di una dropdown da un datatable

Left by Dumps Collection at 28/02/2018 09:16
Gravatar
Hi, great to see your website. I like the content and the research done behind every aspect of your blog. It looks great and very knowledgeable. Keep it up the good work.

# Plan your dream weekend with CHIS!

Left by Country holidays at 19/08/2018 11:46
Gravatar
Plan your dream weekend now! No worry about to budget we provide top class holiday service at budget friendly price.
Comments have been closed on this topic.
«maggio»
domlunmarmergiovensab
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678