<Parameter>
The <Parameter> tag binds a named value to a SQL command parameter (the @name placeholders in your SQL). It's a child tag — you place it inside any data command:
- In forms:
<SelectCommand>,<SubmitCommand>,<DeleteCommand>,<UpdateCommand>,<ControlDataSource> - In views:
<ListDataSource>,<DetailDataSource> - In feeds:
<ListDataSource> - In command buttons: inside the
<Command>tag of<xmod:CommandButton>,<xmod:CommandLink>, and<xmod:CommandImage>
A single command can have as many <Parameter> tags as it needs — typically one per @placeholder in the SQL.
Example
<xmod:Template>
<ListDataSource CommandText="SELECT * FROM Articles WHERE CategoryId = @cat ORDER BY @sort">
<Parameter Name="cat" DefaultValue="0" DataType="Int32" />
<Parameter Name="sort" Value="Headline" />
</ListDataSource>
<DetailDataSource CommandText="SELECT * FROM Articles WHERE ArticleId = @id">
<Parameter Name="id" Value="-1" DataType="Int32" />
</DetailDataSource>
...
</xmod:Template>Properties
| Property | Values | Default | Description |
|---|---|---|---|
| Name * | string | The parameter's name. Used to look up a matching value from the URL/form post when Value is empty. | |
| Value | string | token | The value to bind to the SQL parameter. Optional — see How values are resolved. | |
| DefaultValue | string | token | Fallback value used when Value is empty. | |
| Alias | string | (same as Name) | The SQL parameter name. Set this when the SQL placeholder differs from Name. |
| DataType | DbType | String | The SQL data type — match this to the column type for proper indexing and conversion. |
| Size | integer | (provider default) | The size of a sized type (varchar, nvarchar, char). |
| Direction | Input Output InputOutput ReturnValue | Input | Used for stored procedures that have output parameters or return values. |
* Required property
Property Details
How values are resolved
The single most-misunderstood part of <Parameter> is where the value comes from. XMod Pro looks in three places, in this order, and uses the first one that has a non-empty value:
- The
Valueattribute — if you set it (and it's non-empty after trimming), that value is used. - The
DefaultValueattribute — ifValueis missing or empty, XMod Pro falls back toDefaultValue. - The HTTP request — if both
ValueandDefaultValueare empty, XMod Pro looks for a URL query string or form-post field whose name matchesName. This is most useful in feeds, where callingFeed.aspx?xfd=MyFeed&dept=3will bind3to a<Parameter Name="dept" />automatically.
This ordering explains a common pattern: write Value for the "normal case", and use DefaultValue to keep the page from breaking on the first load (or for callers who don't pass the parameter):
<DetailDataSource CommandText="SELECT * FROM Volunteers WHERE VolunteerId = @vid">
<Parameter Name="vid" Value='<%# FormData("vid") %>'
DefaultValue='<%# UserData("ID") %>' DataType="Int32" />
</DetailDataSource>When an admin links to the page with ?vid=42, Value resolves to 42 and that record loads. When a regular user visits without a vid, Value is empty and DefaultValue resolves to the current user's ID — they edit their own profile. One form, two use cases.
Name: The parameter's name. This serves two purposes:
- It's the key XMod Pro uses to look up an HTTP request parameter when no
ValueorDefaultValueis supplied (see How values are resolved). - It's also the SQL placeholder name unless you set Alias — in which case
Aliasis what gets bound to the SQL command.
- It's the key XMod Pro uses to look up an HTTP request parameter when no
Value: The value to bind to the SQL parameter. Almost always a token or data-binding expression — pulling from a field, the URL, the current user, or another runtime source.
html<Parameter Name="UserId" Value="[[User:ID]]" /> <Parameter Name="ProductId" Value="[[Url:pid]]" /> <Parameter Name="DeptName" Value='<%# Eval("Department") %>' />If the resolved value is an empty string after trimming whitespace, it's treated as missing — XMod Pro will fall through to
DefaultValueand then to the HTTP request. This means a token like[[Url:pid]]that resolves to an empty string when the URL doesn't containpidwill not short-circuit the fallback chain.Set
Value=""(literally an empty string) only if you specifically want to force a NULL or an empty string into the SQL parameter — and even then, the fallback chain may surprise you. The safer pattern is to handle empties in your SQL withISNULL(@param, …).DefaultValue: A fallback used when
Valueis empty. This is what makes the same data command work for both an explicit "edit this record" caller (URL passes the id) and a "default to my own profile" caller (no id in URL — fall back to the current user). WithoutDefaultValue, you'd need separate forms or extra SQL conditionals.Use DefaultValue, not a literal Value, for guard rails
On the very first load of a
<DetailDataSource>whose parameter comes from a button click, the parameter has no value yet. SettingDefaultValue="-1"(for an integer ID column where IDs are always positive) ensures no record matches and the detail area starts empty rather than showing the first record in the table by accident. Tutorial 7 shows this pattern.Alias: The name used to bind to the SQL command — i.e. the
@xxxplaceholder in yourCommandText. Defaults toName. Set it when the URL/form parameter name and the SQL parameter name need to differ.Example: a URL passes
?id=5, but your SQL uses@UserId:html<ListDataSource CommandText="SELECT * FROM Users WHERE UserId = @UserId"> <Parameter Name="id" Alias="UserId" DataType="Int32" /> </ListDataSource>Now
Feed.aspx?xfd=...&id=5binds the URL'sid=5to the SQL's@UserId. The same applies the other direction — when a button passes<Parameter Name="ProductId" />to a target template's data source whose SQL uses@pid, you'd setAlias="pid".If the URL or form parameter name already matches the SQL placeholder, leave
Aliasoff — XMod Pro will useNameas both.DataType: A DbType value —
String(the default),Int32,Int64,Boolean,DateTime,Decimal,Double,Guid, and others.Setting
DataTypematters more than it looks. Without it, every parameter is bound asnvarchar(DbType.String), which forces SQL Server to do an implicit conversion when comparing to non-string columns. That conversion can defeat indexes — turning a millisecond indexed seek into a multi-second table scan on large tables.Rule of thumb: set
DataTypewhenever the column it's compared against isn'tnvarchar/varchar.html<Parameter Name="UserId" DataType="Int32" /> <!-- INT column --> <Parameter Name="DueDate" DataType="DateTime" /> <!-- DATETIME column --> <Parameter Name="IsActive" DataType="Boolean" /> <!-- BIT column --> <Parameter Name="Price" DataType="Decimal" /> <!-- DECIMAL/MONEY column -->Size: For sized types (
String,AnsiString,Binary), the maximum length. You usually don't need to set this for input parameters — the provider sizes them automatically based on the value. Always setSizewhenDirectionisOutputandDataTypeis a string type, otherwise SQL Server returns only the first character.html<Parameter Name="ResultMessage" Direction="Output" DataType="String" Size="500" />Direction: Used with stored procedures to capture output parameters or the procedure's return value. Combine with SubmitCommand (in forms) or ListDataSource (in views) to get the result back into XMod Pro.
Direction Use Input(default)Pass a value into the command — the everyday case. OutputCapture an output parameter from a stored procedure. The value is available afterwards via the [[Posted:Name]]token.ReturnValueCapture the procedure's RETURNvalue.InputOutputPass a value in and read it back out. html<SubmitCommand CommandText="exec InsertOrder"> <Parameter Name="CustomerId" Value='<%# FormData("CustomerId") %>' DataType="Int32" /> <Parameter Name="OrderId" Direction="Output" DataType="Int32" /> <Parameter Name="Status" Direction="ReturnValue" DataType="Int32" /> </SubmitCommand>On a successful submit,
[[Posted:OrderId]]and[[Posted:Status]]are available in the form's success template and in any post-submit redirect.Make Output names unique
For output and return parameters, use a
Namethat doesn't collide with any of your form'sDataFieldvalues. If both an<TextBox DataField="OrderId">and an<Parameter Name="OrderId" Direction="Output">exist, you'll get unpredictable results.
See Also
<ControlDataSource>— uses Parameter for SELECT-driven dropdowns and list controls<AddForm>/<EditForm>— for SubmitCommand, DeleteCommand, and SelectCommand parameter usage<xmod:Template>— for ListDataSource and DetailDataSource parameter usage in views- Tokens overview — the most common source of
ValueandDefaultValue