Parameter.ToString Method
.NET Framework 3.0
Converts the value of this instance to its equivalent string representation.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
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="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>
Community Additions
ADD
Show: