ToString Method

Parameter.ToString Method

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
Not applicable.

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 xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" 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 xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">

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

        </form>
    </body>
</html>

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2016 Microsoft