|
Demonstrates: Search form for SelectParameters, wild character, EmptyDataTemplate property, DropDown pager style, hyperlinks as command buttons
Demonstrates a search form that filters the database results. The user can filter
either by company name or by id. The company name can be searched with wildcard
matching by using the '%' symbol. On select the search criteria entered in the textboxes
is automatically extracted by the SelectParameters collection and passed to the
select command. The SmartDataSource.MonitorParameters property is enabled. In this
way SmartDataSource automatically triggers data rebinding if some of the search
criteria changes.
The SmartDBView.OnEmptyData property determines the behavior when the search results
are empty. In this example it is set to EmptyDataTemplate, which means that the
EmptyDataTemplate template property is rendered in the case of empty dataset. The
page style is set to DropDown.
To quickly create a search form do the following:
- Open the SmartDataSource configuration dialog.
- Add parameters to the SelectParameters or FilterParameters collection. Set the Type
of the parameters - String, Decimal, Boolean, etc.To change the type click the "Show
advanced properties" in order to show the property grid of the parameters.
- Edit the Select command or the FilterExpression in order to use the new parameters.
- From the SmartDataSource smart-tag panel select either "Create Select Search Panel"
or "Create Filter Search Panel". This will create new user interface controls and
configure the parameters to extract their values from the new controls.
- If you are expecting NULL values for the parameters set the property CancelSelectOnNullParameter
of SmartDataSource to False.
The user could specify no search criteria. In this case the parameter values will
be NULL. If you want the parameter to be ignored when it is NULL you can use the
following construct in the WHERE clause of the SELECT statement:
WHERE (CompanyName LIKE @CompanyName
OR @CompanyName IS NULL).
In this way the @CompanyName parameter will filter the values when it is not NULL,
but if it is NULL all data rows will be returned. In order this to work make sure
that the CancelSelectOnNullParameter property of SmartDataSource
is set to False.
CREATE TABLE [dbo].[Shippers] (
[ShipperID] [int] IDENTITY (1, 1) NOT NULL ,
[CompanyName] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Phone] [nvarchar] (24) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
|