Sys.UI.Select and DataTable

Last post 04-04-2006 7:47 PM by Recon_609. 2 replies.

Sort Posts:

  • Sys.UI.Select and DataTable

    04-04-2006, 10:37 AM
    • Member
      405 point Member
    • Recon_609
    • Member since 03-05-2005, 6:48 PM
    • Posts 89
    I have a listbox (Sys.UI.Select) and I want to bind my  Sys.Data.DataTable that I have created in javascript.  How do I bind that DataTable to the listbox in Atlas javascript?
  • Re: Sys.UI.Select and DataTable

    04-04-2006, 1:47 PM
    • Contributor
      7,416 point Contributor
    • Garbin
    • Member since 09-17-2004, 12:35 PM
    • Sassari, Italy
    • Posts 1,506
    • ASPInsiders
      TrustedFriends-MVPs

    Hi,

    check the following example. Hope it helps.

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Web.Services" %>

    <script runat="server">
        [WebMethod]
        public DataTable GetDummyDataTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("ID", typeof(int)));
            dt.Columns.Add(new DataColumn("Name", typeof(String)));
            dt.Columns.Add(new DataColumn("LastName", typeof(String)));

            dt.Rows.Add(1, "John", "Doe");
            dt.Rows.Add(2, "John", "Smith");

            return dt;
        }
    </script>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>ListBox Databinding Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
       
        <atlas:ScriptManager ID="sm" runat="server" />
       
        <div>
            <select id="myListBox"></select>
        </div>
        <div>
            <span>Selected Value is </span>
            <span id="myLabel"></span>
        </div>
        </form>
        <script type="text/javascript">
            function populateList() {
                PageMethods.GetDummyDataTable(onGetComplete);
            }
            function onGetComplete(result) {
                var myListBox = Sys.Application.findObject('myListBox');
               
                myListBox.set_data(result);
            }
        </script>
        <script type="text/xml-script">
            <page>
                <components>
                    <select id="myListBox"
                            textProperty="LastName"
                            valueProperty="ID"
                            firstItemText="Make Your Selection"
                            />
                           
                    <label id="myLabel">
                        <bindings>
                            <binding dataContext="myListBox"
                                     dataPath="selectedValue"
                                     property="text"
                                     />
                        </bindings>
                    </label>
                   
                    <application load="populateList" />
                </components>
            </page>
        </script>
    </body>
    </html>

    Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action
  • Re: Sys.UI.Select and DataTable

    04-04-2006, 7:47 PM
    • Member
      405 point Member
    • Recon_609
    • Member since 03-05-2005, 6:48 PM
    • Posts 89

    Excellent!

    Thank you for the sample.

Page 1 of 1 (3 items)