Export (0) Print
Expand All

Parameter.ToString Method

Note: This method is new in the .NET Framework version 2.0.

Converts the value of this instance to its equivalent string representation.

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

public override string ToString ()
public String ToString ()
public override function ToString () : String

Return Value

A string representation of the value of this instance.

The ToString method returns the Name property of the Parameter object. If the Parameter object has no name, ToString returns String.Empty.

The following code example demonstrates how to access various properties of a Parameter object, including its Name and Type properties.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
 private void Page_Load(object sender, EventArgs e) {

    SqlDataSource sqlSource = 
        new SqlDataSource(ConfigurationManager.ConnectionStrings["MyNorthwind"].ConnectionString,
                          "SELECT * From Employees where EmployeeID = @employee");
    
    // When a Parameter is not named, Name returns String.Empty.
    Parameter userID = new Parameter();

    if (userID.Name.Equals(String.Empty)) {
        Response.Write("Name is Empty<BR>");
    }

    if (null == userID.Name) {
        Response.Write("Name is Null<BR>");
    }

    // Set the Name of the Parameter
    userID.Name = "employee";

    // The Parameter.DefaultValue property is used to bind a static String.
    userID.DefaultValue = "3";

    // The ToString method returns the Name of the Parameter.
    Response.Write(userID.ToString() + "<BR>");
    Response.Write(userID.Name + "<BR>");

    // The default Type of the Parameter is TypeCode.Object
    Response.Write(userID.Type.ToString() + "<BR>");

    sqlSource.SelectParameters.Add(userID);
    Page.Controls.Add(sqlSource);

    GridView grid = new GridView();
    grid.DataSource = sqlSource;
    grid.DataBind();

    PlaceHolder1.Controls.Add(grid);
}
</SCRIPT>

<HTML>
    <BODY>
        <FORM runat="server">

       <asp:PlaceHolder id="PlaceHolder1" runat="server"/>

        </FORM>
    </BODY>
</HTML>

<%@ Page Language="VJ#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
 private void Page_Load(Object sender, System.EventArgs e)
 {
    SqlDataSource sqlSource = new SqlDataSource("Data Source=localhost;" 
        + "Integrated Security=SSPI;Initial Catalog=Northwind;", "SELECT * " 
        + "From Employees where EmployeeID = @employee");
    
    // When a Parameter is not named, Name returns String.Empty.
    Parameter userID = new Parameter();

    if (userID.get_Name().Equals("")) {
        get_Response().Write("Name is Empty<BR>");
    }

    if (null == userID.get_Name()) {
        get_Response().Write("Name is Null<BR>");
    }

    // Set the Name of the Parameter
    userID.set_Name("employee");

    // The Parameter.DefaultValue property is used to bind a static String.
    userID.set_DefaultValue("3");

    // The ToString method returns the Name of the Parameter.
    get_Response().Write(userID.ToString() + "<BR>");
    get_Response().Write(userID.get_Name() + "<BR>");

    // The default Type of the Parameter is TypeCode.Object
    get_Response().Write(userID.get_Type().ToString() + "<BR>");

    sqlSource.get_SelectParameters().Add(userID);
    get_Page().get_Controls().Add(sqlSource);

    GridView grid = new GridView();
    grid.set_DataSource(sqlSource);
    grid.DataBind();
        
    PlaceHolder1.get_Controls().Add(grid);
} //Page_Load

</SCRIPT>

<HTML>
    <BODY>
        <FORM runat="server">

       <asp:PlaceHolder id="PlaceHolder1" runat="server"/>

        </FORM>
    </BODY>
</HTML>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft