我总是从 Parameter 甚至 SqlDataSource 派生一个新类来更改我想要的默认行为。
public class MyDataSource : SqlDataSource
{
public MyDataSource()
{
if (HttpContext.Current != null)
{
this.ConnectionString = MyCinfig.ConnectionString;
SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
CancelSelectOnNullParameter = false;
this.Updated += new SqlDataSourceStatusEventHandler(NXSDataSource_iudExecuted);
this.Inserted += new SqlDataSourceStatusEventHandler(NXSDataSource_iudExecuted);
this.Deleted += new SqlDataSourceStatusEventHandler(NXSDataSource_iudExecuted);
}
}
}
对于参数
public class UserIDParameter : Parameter
{
public UserIDParameter()
{
this.Name = "user_id";
this.DbType = System.Data.DbType.Int32;
}
protected override object Evaluate(System.Web.HttpContext context, System.Web.UI.Control control)
{
return GetMyCurrentUserID();
}
}