ASP.NET Logo Back to WebMatrix Home

 
ASP.NET Mobile Development
Add Mobile Controls
In this walkthrough, you will add an ObjectList server control to the Mobile page you developed in the previous walkthrough.
  1. From the Mobile Controls tab in the Toolbox, drag an ObjectList control onto the Mobile page inside the form named Form1.

    Add Mobile Control

     

  2. Set the ID property of the ObjectList to OrderList.

     
  3. Select the Code tab.

     
  4. From the Code Builders tab in the Toolbox, drag a SELECT Data Method Code Builder onto the bottom of the ASP.NET page.

     
  5. You will see the Connect to Database dialog box appear.

     
  6. Type localhost in the Server box (default).

     
  7. Click the Database drop-down. ASP.NET Web Matrix will connect to the data source and populate the Database drop-down with database names. Select the Orders database.

     
  8. Click OK.

     
  9. You will see step one of the Code Builder Wizard appear; it is called the Construct SELECT Query dialog box.

     
  10. Select Orders in the Tables list view.

     
  11. Select the check box next to the * item in the Columns list view.

     
  12. Click Next.

     
  13. You will see step two of the Code Builder Wizard appear; it is called the Query Preview dialog box.

     
  14. Click Test Query.

     
  15. You will see the Orders rows appear in the Query Preview dialog box results grid.

     
  16. Click Next.

     
  17. You will see step three of the Code Builder Wizard appear. Type GetOrders into the method name box.

     
  18. Select the DataSet radio button (default).

     
  19. Click Finish.

     
  20. The Wizard will close and ASP.NET Web Matrix will place a function called GetOrders in Code view. The function accepts no input parameters and returns a DataSet as an output parameter. The DataSet is populated with all of the OrderIDs in the Orders table:

     

    Function GetOrders() As System.Data.DataSet
        Dim connectionString As String = _
            "server='localhost'; trusted_connection=true; Database='Orders'"
            
        Dim sqlConnection As System.Data.SqlClient.SqlConnection = _
            New System.Data.SqlClient.SqlConnection(connectionString)
        
        Dim queryString As String = "SELECT [Orders].* FROM [Orders]"
        
        Dim sqlCommand As System.Data.SqlClient.SqlCommand = _
            New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
        
        Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = _
            New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
            
        Dim dataSet As System.Data.DataSet = New System.Data.DataSet
        
        dataAdapter.Fill(dataSet)
        
        Return dataSet
    End Function
    
  21. Add Page_Load event code that binds the ObjectList with the results of calling the GetOrders function:

     

    Sub Page_Load(Sender As Object, E As EventArgs)
    
        OrderList.DataSource = GetOrders()
        OrderList.DataBind() 
    
    End Sub
    
  22. Click the Start button or press F5 to run the page. This will test the page with a web browser client. 

     
  23. Click on an OrderID link to view the Orders table details. 

    My First Mobile Page Details

  24. Alternatively, you can now test the page against a mobile device emulator or with a mobile cell phone or PDA. The page will automatically adjust its output markup (for example: emiting WML for WAP devices).

     
  25. Close the Web browser instance.

Next Step >>