| |
| 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.
- From the Mobile Controls tab in the Toolbox, drag an
ObjectList control onto the Mobile page inside the form named Form1.
- Set the ID property of the ObjectList to OrderList.
- Select the Code tab.
- From the Code Builders tab in the Toolbox, drag a
SELECT Data Method Code Builder onto the bottom of the ASP.NET
page.
- You will see the Connect to Database dialog box appear.
- Type localhost in the Server box (default).
- 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.
- Click OK.
- You will see step one of the Code Builder Wizard appear; it is
called the Construct SELECT Query dialog box.
- Select Orders in the Tables list view.
- Select the check box next to the * item in the Columns
list view.
- Click Next.
- You will see step two of the Code Builder Wizard appear; it is
called the Query Preview dialog box.
- Click Test Query.
- You will see the Orders rows appear in the Query Preview
dialog box results grid.
- Click Next.
- You will see step three of the Code Builder Wizard appear. Type
GetOrders into the method name box.
- Select the DataSet radio button (default).
- Click Finish.
- 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
- 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
- Click the Start button or press F5 to run the page. This will
test the page with a web browser client.
- Click on an OrderID link to view the Orders table
details.
- 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).
- Close the Web browser instance.
Next Step >> |
|