This documentation is archived and is not being maintained.

Parameter.Name Property

Gets or sets the name of the parameter.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public string Name { get; set; }

Property Value

Type: System.String
The name of the parameter. The default value is String.Empty.

Parameter objects are not required to have a name; however, data source controls might use the parameter name to match a Parameter object in a collection with a parameter in a SQL query or business method signature. For example, the SqlDataSource control can use the name of the Parameter object to match a placeholder in a parameterized SQL query. Similarly, the SqlDataSource control can use the name of a Parameter object in the FilterParameters collection to match a placeholder in the FilterExpression property. In some cases, the name is not used and the order in which the Parameter object is added to a ParameterCollection collection is more important. For more information, see Using Parameters with the SqlDataSource Control and Using Parameters with the ObjectDataSource Control.

If the name of the parameter is changed, the OnParameterChanged method is called.

The following code example demonstrates how to display filtered data using an ObjectDataSource control to retrieve data from a middle-tier business object and a GridView control to display the results. The code example consists of a TextBox control, a GridView control, the ObjectDataSource control, and a Submit button. By default, the TextBox control is populated with the name of one of the Northwind employees. The GridView control displays information about the employee identified by the name in the TextBox control. To retrieve data on another employee, enter the full name of the employee in the TextBox control and click the button.

The FilterExpression property specifies an expression used to filter the data retrieved by the SelectMethod property. It uses parameter placeholders that are evaluated to the parameters contained in the FilterParameters collection. In this example, the parameter placeholder is bounded by single quotation marks because the type of the parameter is a string type that might contain spaces. If the type of the parameter is a numeric or date type, bounding quotation marks are not needed.

This code example is part of a larger example provided for the FilterExpression property of the ObjectDataSource class.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

    protected void ObjectDataSource1_Filtering(object sender, ObjectDataSourceFilteringEventArgs e)
        if (Textbox1.Text == "")
            e.ParameterValues.Add("FullName", "Nancy Davolio");

<html xmlns="" >
    <title>ObjectDataSource - C# Example</title>
    <form id="Form1" method="post" runat="server">

        <p>Show all users with the following name.</p>

        <asp:textbox id="Textbox1" runat="server" text="Nancy Davolio" />

            <asp:boundfield headertext="ID" datafield="EmpID" />
            <asp:boundfield headertext="Name" datafield="FullName" />
            <asp:boundfield headertext="Street Address" datafield="Address" />

        <!-- Security Note: The ObjectDataSource uses a FormParameter,
             Security Note: which does not perform validation of input from the client. -->

          filterexpression="FullName='{0}'" OnFiltering="ObjectDataSource1_Filtering">
              <asp:formparameter name="FullName" formfield="Textbox1" defaultvalue="Nancy Davolio" />

        <p><asp:button id="Button1" runat="server" text="Search" /></p>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.