|
Iron Speed Designer automatically creates dropdown lists on Show Table pages known as “FieldFilters”.
A FieldFilter control filters a table of records based on the value selected in the FieldFilter control
and the values contained in the associated database field.
Normally, a Show Table Page displays all records in a database table or view when the default value in the
FieldFilter is set to “All”. Sometimes you might want to display records specific to some value in a FieldFilter
when the page is initially displayed. The sample code shown below sets the default value of a FieldFilter on a Show
Table Page and filters the data based on the default value set for the FieldFilter.
You can set the default value of a filter when a page loads the first time and filter the data based on the
default value. Handle the Load event in the TableControl class and set the item selected in the FieldFilter.
Then, handle the PreRunQuery event in the TableControl class to filter the page.
Step 1: Create an application based on the Orders table in the Northwind database.
Step 2: Handle the load and PreRunQuery event in the TableControl class of ShowOrdersTablePage.aspx.
For .NET Framework 1.1, add your code customization in the TableControl class of ShowOrdersTablePage.aspx.cs,
located in
|
...\<Application Folder>\Orders\ShowOrdersTablePage.aspx.cs
|
For .NET Framework 2.0, add your code customization in the TableControl class of
ShowOrdersTablePage.Controls.cs, located in
|
...\<Application Folder>\App_Code\Orders\ShowOrdersTablePage.Controls.cs
|
C#:
public OrdersTableControl()
{
this.PreRunQuery += new BaseClasses.IRunsQuery.PreRunQueryEventHandler(OrdersTableControl_PreRunQuery);
this.Load += new EventHandler(OrdersTableControl_Load);
}
private void OrdersTableControl_Load(object sender, System.EventArgs e)
{
if(!this.Page.IsPostBack)
{
BaseClasses.Web.UI.WebControls.DropDownList FilterDropdownList = this.CustomerIDFilterDropDownList;
ListItem myListItem;
myListItem = FilterDropdownList.Items.FindByValue("ALFKI");
int myIndex = FilterDropdownList.Items.IndexOf(myListItem);
FilterDropdownList.SelectedIndex=myIndex;
}
}
private void OrdersTableControl_PreRunQuery(object sender, System.ComponentModel.CancelEventArgs e)
{
if(!this.Page.IsPostBack)
{
string whereStr = "CustomerID='ALFKI'";
this.AddFilter("mytempFilter",whereStr);
}
else
{
this.RemoveFilter("mytempFilter");
}
}
|
Visual Basic .NET:
Private Sub OrdersTableControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Not Me.Page.IsPostBack) Then
Dim FilterDropdownList As BaseClasses.Web.UI.WebControls.DropDownList =
Me.CustomerIDFilterDropDownList
Dim myListItem As ListItem
myListItem = FilterDropdownList.Items.FindByValue("ALFKI")
Dim myIndex As Integer = FilterDropdownList.Items.IndexOf(myListItem)
FilterDropdownList.SelectedIndex = myIndex
End If
End Sub
Private Sub OrdersTableControl_PreRunQuery(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.PreRunQuery
If (Not Me.Page.IsPostBack) Then
Dim myfilter As BaseClasses.Data.BaseFilter
myfilter = Me.GetFilter("mytempFilter")
If (myfilter Is Nothing) Then
Dim whereStr As String
whereStr = "CustomerID='ALFKI'"
Me.AddFilter("mytempFilter", whereStr)
End If
End If
End Sub
|
Step 3: Build and run your application
|