|
Step 1: Create an application in Iron Speed Designer using a database table, such as the Orders table in Northwind.
Step 2: In the HTML layout page file for ShowOrdersTablePage, delete all content between the...
and the...
...tags.
Step 3: Add the following content between the...
and the...
...tags.
<tr>
<td class="tableRowsEdge">
<GEN:ITEMTEMPLATE Name="OrdersTableItem" ></GEN:ITEMTEMPLATE>
<asp:datagrid id="myDataGrid" runat="server">
<HeaderStyle BackColor = "#336699" ForeColor = "#ffffff" Font-Bold = "true" />
<AlternatingItemStyle BackColor = "#eeeeee" />
</asp:datagrid>
</td>
</tr>
|
Step 4: Override the DataBind method in the TableControl class for ShowOrdersTablePage.aspx.
For .NET Framework 1.1, add the code in the TableControl class of ShowOrdersTablePage.aspx.cs located in:
|
...\<Application Folder>\Orders\ShowOrdersTablePage.aspx.cs
|
For .NET Framework 2.0, add the code in TableControl class of ShowOrdersTablePage.Controls.cs located in:
|
...\<Application Folder>\<App_Code>Orders\ShowOrdersTablePage.Controls.cs
|
C#:
public override void DataBind()
{
base.DataBind();
System.Collections.ArrayList myList;
System.Data.DataTable myDataTable;
myList= this.GetRecords();
if(myList!=null)
{
OrdersRecord[] myRecordList ;
//Convert to an array of type OrdersRecord.
myRecordList =(OrdersRecord[])(myList.ToArray(typeof(OrdersRecord)));
//Now convert this array to a datatable.
myDataTable = OrdersTable.Instance.CreateDataTable(myRecordList);
DataGrid myDataGridcontrol =
(System.Web.UI.WebControls.DataGrid)this.Page.FindControlRecursively("myDataGrid");
myDataGridcontrol.DataSource = myDataTable;
myDataGridcontrol.DataBind();
}
}
|
Visual Basic .NET:
Public Overrides Sub DataBind()
MyBase.DataBind()
Dim myList As System.Collections.ArrayList
Dim myDataTable As System.Data.DataTable
myList = Me.GetRecords()
If Not (IsNothing(myList)) Then
Dim myRecordsList As OrdersRecord()
'Convert to an array of type OrdersRecord.
myRecordsList = CType(myList.ToArray(GetType(OrdersRecord)), OrdersRecord())
'Now convert this array to a datatable.
myDataTable = OrdersTable.Instance.CreateDataTable(myRecordsList)
'Now you can use the myDataTable and set it as the source of a data grid
Dim myDataGridcontrol As DataGrid =
CType(Me.Page.FindControlRecursively("myDataGrid"), System.Web.UI.WebControls.DataGrid)
myDataGridcontrol.DataSource = myDataTable
myDataGridcontrol.DataBind()
End If
End Sub
|
Note that myDataGrid is the ID of the ASP .NET data grid.
|