本文整理汇总了C#中System.Web.UI.WebControls.Parameter类的典型用法代码示例。如果您正苦于以下问题:C# Parameter类的具体用法?C# Parameter怎么用?C# Parameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Parameter类属于System.Web.UI.WebControls命名空间,在下文中一共展示了Parameter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
public partial class param1acs_aspx : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
SqlDataSource sqlSource = new SqlDataSource(
ConfigurationManager.ConnectionStrings["MyNorthwind"].ConnectionString,
"SELECT FirstName, LastName FROM Employees WHERE Country = @country;");
ControlParameter country = new ControlParameter();
country.Name = "country";
country.Type = TypeCode.String;
country.ControlID = "DropDownList1";
country.PropertyName = "SelectedValue";
// If the DefaultValue is not set, the DataGrid does not
// display anything on the first page load. This is because
// on the first page load, the DropDownList has no
// selected item, and the ControlParameter evaluates to
// String.Empty.
country.DefaultValue = "USA";
sqlSource.SelectParameters.Add(country);
// Add the SqlDataSource to the page controls collection.
Page.Controls.Add(sqlSource);
DataGrid1.DataSource = sqlSource;
DataGrid1.DataBind();
}
}
示例2: StaticParameter
namespace Samples.AspNet {
using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public class StaticParameter : Parameter {
public StaticParameter() {
}
// The StaticParameter(string, object) constructor
// initializes the DataValue property and calls the
// Parameter(string) constructor to initialize the Name property.
public StaticParameter(string name, object value) : base(name) {
DataValue = value;
}
// The StaticParameter(string, TypeCode, object) constructor
// initializes the DataValue property and calls the
// Parameter(string, TypeCode) constructor to initialize the Name and
// Type properties.
public StaticParameter(string name, TypeCode type, object value) : base(name, type) {
DataValue = value;
}
// The StaticParameter copy constructor is provided to ensure that
// the state contained in the DataValue property is copied to new
// instances of the class.
protected StaticParameter(StaticParameter original) : base(original) {
DataValue = original.DataValue;
}
// The Clone method is overridden to call the
// StaticParameter copy constructor, so that the data in
// the DataValue property is correctly transferred to the
// new instance of the StaticParameter.
protected override Parameter Clone() {
return new StaticParameter(this);
}
// The DataValue can be any arbitrary object and is stored in ViewState.
public object DataValue {
get {
return ViewState["Value"];
}
set {
ViewState["Value"] = value;
}
}
// The Value property is a type safe convenience property
// used when the StaticParameter represents string data.
// It gets the string value of the DataValue property, and
// sets the DataValue property directly.
public string Value {
get {
object o = DataValue;
if (o == null || !(o is string))
return String.Empty;
return (string)o;
}
set {
DataValue = value;
OnParameterChanged();
}
}
// The Evaluate method is overridden to return the
// DataValue property instead of the DefaultValue.
protected override object Evaluate(HttpContext context, Control control) {
if (context.Request == null)
return null;
return DataValue;
}
}
}