2 // System.Web.UI.WebControls.SqlDataSourceView
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Sanjay Gupta (gsanjay@novell.com)
9 // (C) Novell, Inc. (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.Collections.Specialized;
38 using System.ComponentModel;
39 using System.Data.Common;
41 namespace System.Web.UI.WebControls {
42 public class SqlDataSourceView : DataSourceView, IStateManager {
45 DbProviderFactory factory;
46 DbConnection connection;
48 public SqlDataSourceView (SqlDataSource owner, string name, HttpContext context)
53 this.context = context;
56 void InitConnection ()
58 if (factory == null) factory = owner.GetDbProviderFactoryInternal ();
59 if (connection == null) {
60 connection = factory.CreateConnection ();
61 connection.ConnectionString = owner.ConnectionString;
65 public int Delete (IDictionary keys, IDictionary oldValues)
67 return ExecuteDelete (keys, oldValues);
70 protected override int ExecuteDelete (IDictionary keys, IDictionary oldValues)
73 throw new NotSupportedException("Delete operation is not supported");
74 if (oldValues == null && ConflictDetection == ConflictOptions.CompareAllValues)
75 throw new InvalidOperationException ("oldValues parameters should be specified when ConflictOptions is set to CompareAllValues");
79 DbCommand command = factory.CreateCommand ();
80 command.CommandText = DeleteCommand;
81 command.Connection = connection;
82 if (DeleteCommandType == SqlDataSourceCommandType.Text)
83 command.CommandType = CommandType.Text;
85 command.CommandType = CommandType.StoredProcedure;
87 IDictionary oldDataValues;
88 if (ConflictDetection == ConflictOptions.CompareAllValues) {
89 oldDataValues = new Hashtable ();
91 foreach (DictionaryEntry de in keys)
92 oldDataValues [de.Key] = de.Value;
94 if (oldValues != null) {
95 foreach (DictionaryEntry de in oldValues)
96 oldDataValues [de.Key] = de.Value;
100 oldDataValues = keys;
102 InitializeParameters (command, DeleteParameters, null, oldDataValues, true);
104 SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
109 bool closed = connection.State == ConnectionState.Closed;
113 Exception exception = null;
116 result = command.ExecuteNonQuery();
117 } catch (Exception e) {
124 OnDataSourceViewChanged (EventArgs.Empty);
126 SqlDataSourceStatusEventArgs deletedArgs =
127 new SqlDataSourceStatusEventArgs (command, result, exception);
128 OnDeleted (deletedArgs);
130 if (exception != null && !deletedArgs.ExceptionHandled)
136 public int Insert (IDictionary values)
138 return ExecuteInsert (values);
141 protected override int ExecuteInsert (IDictionary values)
144 throw new NotSupportedException ("Insert operation is not supported");
148 DbCommand command = factory.CreateCommand ();
149 command.CommandText = InsertCommand;
150 command.Connection = connection;
151 if (InsertCommandType == SqlDataSourceCommandType.Text)
152 command.CommandType = CommandType.Text;
154 command.CommandType = CommandType.StoredProcedure;
156 InitializeParameters (command, InsertParameters, values, null, false);
158 SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
163 bool closed = connection.State == ConnectionState.Closed;
166 Exception exception = null;
169 result = command.ExecuteNonQuery ();
171 catch (Exception e) {
178 OnDataSourceViewChanged (EventArgs.Empty);
180 OnInserted (new SqlDataSourceStatusEventArgs (command, result, exception));
182 if (exception != null)
187 public IEnumerable Select (DataSourceSelectArguments arguments)
189 return ExecuteSelect (arguments);
192 protected internal override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
194 if (SortParameterName.Length > 0 && SelectCommandType == SqlDataSourceCommandType.Text)
195 throw new NotSupportedException ("The SortParameterName property is only supported with stored procedure commands in SqlDataSource");
197 if (arguments.SortExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
198 throw new NotSupportedException ("SqlDataSource cannot sort. Set DataSourceMode to DataSet to enable sorting.");
200 if (arguments.StartRowIndex > 0 || arguments.MaximumRows > 0)
201 throw new NotSupportedException ("SqlDataSource does not have paging enabled. Set the DataSourceMode to DataSet to enable paging.");
203 if (FilterExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
204 throw new NotSupportedException ("SqlDataSource only supports filtering when the data source's DataSourceMode is set to DataSet.");
208 DbCommand command = factory.CreateCommand ();
209 command.CommandText = SelectCommand;
210 command.Connection = connection;
211 if (SelectCommandType == SqlDataSourceCommandType.Text)
212 command.CommandType = CommandType.Text;
214 command.CommandType = CommandType.StoredProcedure;
215 if (SortParameterName.Length > 0 && arguments.SortExpression.Length > 0)
216 command.Parameters.Add (CreateDbParameter (SortParameterName, arguments.SortExpression));
219 if (SelectParameters.Count > 0)
220 InitializeParameters (command, SelectParameters, null, null, false);
222 Exception exception = null;
223 if (owner.DataSourceMode == SqlDataSourceMode.DataSet) {
224 DataView dataView = null;
226 if (owner.EnableCaching)
227 dataView = (DataView) owner.Cache.GetCachedObject (SelectCommand, SelectParameters);
229 if (dataView == null) {
230 SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
231 OnSelecting (selectingArgs);
232 if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
236 DbDataAdapter adapter = factory.CreateDataAdapter ();
237 DataSet dataset = new DataSet ();
239 adapter.SelectCommand = command;
240 adapter.Fill (dataset, name);
242 dataView = dataset.Tables [0].DefaultView;
243 if (dataView == null)
244 throw new InvalidOperationException ();
246 catch (Exception e) {
249 int rowsAffected = (dataView == null) ? 0 : dataView.Count;
250 SqlDataSourceStatusEventArgs selectedArgs = new SqlDataSourceStatusEventArgs (command, rowsAffected, exception);
251 OnSelected (selectedArgs);
253 if (exception != null && !selectedArgs.ExceptionHandled)
256 if (owner.EnableCaching)
257 owner.Cache.SetCachedObject (SelectCommand, selectParameters, dataView);
260 if (SortParameterName.Length == 0 || SelectCommandType == SqlDataSourceCommandType.Text)
261 dataView.Sort = arguments.SortExpression;
263 if (FilterExpression.Length > 0) {
264 IOrderedDictionary fparams = FilterParameters.GetValues (context, owner);
265 SqlDataSourceFilteringEventArgs fargs = new SqlDataSourceFilteringEventArgs (fparams);
268 object [] formatValues = new object [fparams.Count];
269 for (int n = 0; n < formatValues.Length; n++) {
270 formatValues [n] = fparams [n];
271 if (formatValues [n] == null) return dataView;
273 dataView.RowFilter = string.Format (FilterExpression, formatValues);
280 SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
281 OnSelecting (selectingArgs);
282 if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
286 DbDataReader reader = null;
287 bool closed = connection.State == ConnectionState.Closed;
292 reader = command.ExecuteReader (closed ? CommandBehavior.CloseConnection : CommandBehavior.Default);
294 catch (Exception e) {
297 SqlDataSourceStatusEventArgs selectedArgs =
298 new SqlDataSourceStatusEventArgs (command, reader.RecordsAffected, exception);
299 OnSelected (selectedArgs);
300 if (exception != null && !selectedArgs.ExceptionHandled)
307 static bool PrepareNullParameters (DbCommand command, bool cancelIfHas)
309 for (int i = 0; i < command.Parameters.Count; i++) {
310 DbParameter param = command.Parameters [i];
311 if (param.Value == null && ((param.Direction & ParameterDirection.Input) != 0)) {
315 param.Value = DBNull.Value;
321 public int Update (IDictionary keys, IDictionary values, IDictionary oldValues)
323 return ExecuteUpdate (keys, values, oldValues);
326 protected override int ExecuteUpdate (IDictionary keys, IDictionary values, IDictionary oldValues)
329 throw new NotSupportedException ("Update operation is not supported");
330 if (oldValues == null && ConflictDetection == ConflictOptions.CompareAllValues)
331 throw new InvalidOperationException ("oldValues parameters should be specified when ConflictOptions is set to CompareAllValues");
335 DbCommand command = factory.CreateCommand ();
336 command.CommandText = UpdateCommand;
337 command.Connection = connection;
338 if (UpdateCommandType == SqlDataSourceCommandType.Text)
339 command.CommandType = CommandType.Text;
341 command.CommandType = CommandType.StoredProcedure;
343 IDictionary oldDataValues;
344 if (ConflictDetection == ConflictOptions.CompareAllValues) {
345 oldDataValues = new OrderedDictionary ();
347 foreach (DictionaryEntry de in keys)
348 oldDataValues [de.Key] = de.Value;
350 if (oldValues != null) {
351 foreach (DictionaryEntry de in oldValues)
352 oldDataValues [de.Key] = de.Value;
356 oldDataValues = keys;
359 IDictionary dataValues = values;
361 InitializeParameters (command, UpdateParameters, dataValues, oldDataValues, ConflictDetection == ConflictOptions.OverwriteChanges);
363 SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
368 bool closed = connection.State == ConnectionState.Closed;
371 Exception exception = null;
374 result = command.ExecuteNonQuery ();
376 catch (Exception e) {
383 OnDataSourceViewChanged (EventArgs.Empty);
385 SqlDataSourceStatusEventArgs updatedArgs =
386 new SqlDataSourceStatusEventArgs (command, result, exception);
387 OnUpdated (updatedArgs);
389 if (exception != null && !updatedArgs.ExceptionHandled)
395 string FormatOldParameter (string name)
397 string f = OldValuesParameterFormatString;
399 return String.Format (f, name);
404 object FindValueByName (string parameterName, IDictionary values, bool format)
409 foreach (DictionaryEntry de in values) {
410 string valueName = format == true ? FormatOldParameter (de.Key.ToString ()) : de.Key.ToString ();
411 if (String.Compare(parameterName, valueName, StringComparison.InvariantCultureIgnoreCase) == 0)
412 return values [de.Key];
417 void InitializeParameters (DbCommand command, ParameterCollection parameters, IDictionary values, IDictionary oldValues, bool parametersMayMatchOldValues)
419 IOrderedDictionary parameterValues = parameters.GetValues (context, owner);
421 foreach (string parameterName in parameterValues.Keys) {
422 Parameter p = parameters [parameterName];
423 object value = FindValueByName (parameterName, values, false);
424 string valueName = parameterName;
426 value = FindValueByName (parameterName, oldValues, true);
428 if (value == null && parametersMayMatchOldValues) {
429 value = FindValueByName (parameterName, oldValues, false);
430 valueName = FormatOldParameter (parameterName);
434 object dbValue = p.ConvertValue (value);
435 DbParameter newParameter = CreateDbParameter (valueName, dbValue, p.Direction, p.Size);
436 if (!command.Parameters.Contains (newParameter.ParameterName)) {
437 command.Parameters.Add (newParameter);
441 command.Parameters.Add (CreateDbParameter (p.Name, parameterValues [parameterName], p.Direction, p.Size));
445 if (values != null) {
446 foreach (DictionaryEntry de in values)
447 if (!command.Parameters.Contains (ParameterPrefix + (string) de.Key))
448 command.Parameters.Add (CreateDbParameter ((string) de.Key, de.Value));
451 if (oldValues != null) {
452 foreach (DictionaryEntry de in oldValues)
453 if (!command.Parameters.Contains (ParameterPrefix + FormatOldParameter ((string) de.Key)))
454 command.Parameters.Add (CreateDbParameter (FormatOldParameter ((string) de.Key), de.Value));
458 private DbParameter CreateDbParameter (string name, object value)
460 return CreateDbParameter (name, value, ParameterDirection.Input, -1);
463 private DbParameter CreateDbParameter (string name, object value, ParameterDirection dir, int size)
465 DbParameter dbp = factory.CreateParameter ();
466 dbp.ParameterName = ParameterPrefix + name;
475 void IStateManager.LoadViewState (object savedState)
477 LoadViewState (savedState);
480 object IStateManager.SaveViewState ()
482 return SaveViewState ();
485 void IStateManager.TrackViewState ()
490 protected virtual void LoadViewState (object savedState)
492 object [] vs = savedState as object [];
496 if (vs [0] != null) ((IStateManager) deleteParameters).LoadViewState (vs [0]);
497 if (vs [1] != null) ((IStateManager) filterParameters).LoadViewState (vs [1]);
498 if (vs [2] != null) ((IStateManager) insertParameters).LoadViewState (vs [2]);
499 if (vs [3] != null) ((IStateManager) selectParameters).LoadViewState (vs [3]);
500 if (vs [4] != null) ((IStateManager) updateParameters).LoadViewState (vs [4]);
503 protected virtual object SaveViewState ()
505 object [] vs = new object [5];
507 if (deleteParameters != null) vs [0] = ((IStateManager) deleteParameters).SaveViewState ();
508 if (filterParameters != null) vs [1] = ((IStateManager) filterParameters).SaveViewState ();
509 if (insertParameters != null) vs [2] = ((IStateManager) insertParameters).SaveViewState ();
510 if (selectParameters != null) vs [3] = ((IStateManager) selectParameters).SaveViewState ();
511 if (updateParameters != null) vs [4] = ((IStateManager) updateParameters).SaveViewState ();
513 foreach (object o in vs)
514 if (o != null) return vs;
518 protected virtual void TrackViewState ()
522 if (filterParameters != null) ((IStateManager) filterParameters).TrackViewState ();
523 if (selectParameters != null) ((IStateManager) selectParameters).TrackViewState ();
526 bool IStateManager.IsTrackingViewState {
527 get { return IsTrackingViewState; }
530 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
531 private bool cancelSelectOnNullParameter = true;
532 public bool CancelSelectOnNullParameter {
533 get { return cancelSelectOnNullParameter; }
535 if (CancelSelectOnNullParameter == value)
537 cancelSelectOnNullParameter = value;
538 OnDataSourceViewChanged (EventArgs.Empty);
542 public override bool CanDelete {
543 get { return DeleteCommand != null && DeleteCommand != ""; }
546 public override bool CanInsert {
547 get { return InsertCommand != null && InsertCommand != ""; }
550 public override bool CanPage {
551 /* according to MS, this is false in all cases */
552 get { return false; }
555 public override bool CanRetrieveTotalRowCount {
556 /* according to MS, this is false in all cases */
557 get { return false; }
560 public override bool CanSort {
562 /* we can sort if we're a DataSet, regardless of sort parameter name.
563 we can sort if we're a DataReader, if the sort parameter name is not null/"".
565 return (owner.DataSourceMode == SqlDataSourceMode.DataSet
566 || (SortParameterName != null && SortParameterName != ""));
570 public override bool CanUpdate {
571 get { return UpdateCommand != null && UpdateCommand != ""; }
574 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
575 private ConflictOptions conflictDetection = ConflictOptions.OverwriteChanges;
576 public ConflictOptions ConflictDetection {
577 get { return conflictDetection; }
579 if (ConflictDetection == value)
581 conflictDetection = value;
582 OnDataSourceViewChanged (EventArgs.Empty);
586 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
587 private string deleteCommand = "";
588 public string DeleteCommand {
589 get { return deleteCommand; }
590 set { deleteCommand = value; }
593 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
594 private SqlDataSourceCommandType deleteCommandType = SqlDataSourceCommandType.Text;
595 public SqlDataSourceCommandType DeleteCommandType {
596 get { return deleteCommandType; }
597 set { deleteCommandType = value; }
600 [DefaultValueAttribute (null)]
601 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
602 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
603 public ParameterCollection DeleteParameters {
604 get { return GetParameterCollection (ref deleteParameters, false, false); }
607 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
608 private string filterExpression;
609 public string FilterExpression {
610 get { return filterExpression ?? string.Empty; }
612 if (FilterExpression == value)
614 filterExpression = value;
615 OnDataSourceViewChanged (EventArgs.Empty);
619 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
620 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
621 [DefaultValueAttribute (null)]
622 public ParameterCollection FilterParameters {
623 get { return GetParameterCollection (ref filterParameters, true, true); }
626 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
627 private string insertCommand = "";
628 public string InsertCommand {
629 get { return insertCommand; }
630 set { insertCommand = value; }
633 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
634 private SqlDataSourceCommandType insertCommandType = SqlDataSourceCommandType.Text;
635 public SqlDataSourceCommandType InsertCommandType {
636 get { return insertCommandType; }
637 set { insertCommandType = value; }
640 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
641 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
642 [DefaultValueAttribute (null)]
643 public ParameterCollection InsertParameters {
644 get { return GetParameterCollection (ref insertParameters, false, false); }
647 protected bool IsTrackingViewState {
648 get { return tracking; }
651 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
652 private string oldValuesParameterFormatString = "{0}";
653 [DefaultValue ("{0}")]
654 public string OldValuesParameterFormatString {
655 get { return oldValuesParameterFormatString; }
657 if (OldValuesParameterFormatString == value)
659 oldValuesParameterFormatString = value;
660 OnDataSourceViewChanged (EventArgs.Empty);
664 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
665 private string selectCommand;
666 public string SelectCommand {
667 get { return selectCommand != null ? selectCommand : string.Empty; }
669 if (SelectCommand == value)
671 selectCommand = value;
672 OnDataSourceViewChanged (EventArgs.Empty);
676 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
677 private SqlDataSourceCommandType selectCommandType = SqlDataSourceCommandType.Text;
678 public SqlDataSourceCommandType SelectCommandType {
679 get { return selectCommandType; }
680 set { selectCommandType = value; }
683 public ParameterCollection SelectParameters {
684 get { return GetParameterCollection (ref selectParameters, true, true); }
687 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
688 private string sortParameterName = "";
689 public string SortParameterName {
690 get { return sortParameterName; }
692 if (SortParameterName == value)
694 sortParameterName = value;
695 OnDataSourceViewChanged (EventArgs.Empty);
699 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
700 private string updateCommand = "";
701 public string UpdateCommand {
702 get { return updateCommand; }
703 set { updateCommand = value; }
706 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
707 private SqlDataSourceCommandType updateCommandType = SqlDataSourceCommandType.Text;
708 public SqlDataSourceCommandType UpdateCommandType {
709 get { return updateCommandType; }
710 set { updateCommandType = value; }
713 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
714 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
715 [DefaultValueAttribute (null)]
716 public ParameterCollection UpdateParameters {
717 get { return GetParameterCollection (ref updateParameters, false, false); }
720 void ParametersChanged (object source, EventArgs args)
722 OnDataSourceViewChanged (EventArgs.Empty);
725 ParameterCollection GetParameterCollection (ref ParameterCollection output, bool propagateTrackViewState, bool subscribeChanged)
730 output = new ParameterCollection ();
732 output.ParametersChanged += new EventHandler (ParametersChanged);
734 if (IsTrackingViewState && propagateTrackViewState)
735 ((IStateManager) output).TrackViewState ();
740 protected virtual string ParameterPrefix {
742 switch (owner.ProviderName) {
744 case "System.Data.SqlClient": return "@";
745 case "System.Data.OracleClient": return ":";
751 ParameterCollection deleteParameters;
752 ParameterCollection filterParameters;
753 ParameterCollection insertParameters;
754 ParameterCollection selectParameters;
755 ParameterCollection updateParameters;
763 static readonly object EventDeleted = new object ();
764 protected virtual void OnDeleted (SqlDataSourceStatusEventArgs e)
766 if (!HasEvents ()) return;
767 SqlDataSourceStatusEventHandler h = Events [EventDeleted] as SqlDataSourceStatusEventHandler;
772 public event SqlDataSourceStatusEventHandler Deleted {
773 add { Events.AddHandler (EventDeleted, value); }
774 remove { Events.RemoveHandler (EventDeleted, value); }
777 static readonly object EventDeleting = new object ();
778 protected virtual void OnDeleting (SqlDataSourceCommandEventArgs e)
780 if (!HasEvents ()) return;
781 SqlDataSourceCommandEventHandler h = Events [EventDeleting] as SqlDataSourceCommandEventHandler;
785 public event SqlDataSourceCommandEventHandler Deleting {
786 add { Events.AddHandler (EventDeleting, value); }
787 remove { Events.RemoveHandler (EventDeleting, value); }
792 static readonly object EventFiltering = new object ();
793 protected virtual void OnFiltering (SqlDataSourceFilteringEventArgs e)
795 if (!HasEvents ()) return;
796 SqlDataSourceFilteringEventHandler h = Events [EventFiltering] as SqlDataSourceFilteringEventHandler;
800 public event SqlDataSourceFilteringEventHandler Filtering {
801 add { Events.AddHandler (EventFiltering, value); }
802 remove { Events.RemoveHandler (EventFiltering, value); }
807 static readonly object EventInserted = new object ();
808 protected virtual void OnInserted (SqlDataSourceStatusEventArgs e)
810 if (!HasEvents ()) return;
811 SqlDataSourceStatusEventHandler h = Events [EventInserted] as SqlDataSourceStatusEventHandler;
816 public event SqlDataSourceStatusEventHandler Inserted {
817 add { Events.AddHandler (EventInserted, value); }
818 remove { Events.RemoveHandler (EventInserted, value); }
821 static readonly object EventInserting = new object ();
822 protected virtual void OnInserting (SqlDataSourceCommandEventArgs e)
824 if (!HasEvents ()) return;
825 SqlDataSourceCommandEventHandler h = Events [EventInserting] as SqlDataSourceCommandEventHandler;
829 public event SqlDataSourceCommandEventHandler Inserting {
830 add { Events.AddHandler (EventInserting, value); }
831 remove { Events.RemoveHandler (EventInserting, value); }
836 static readonly object EventSelected = new object ();
837 protected virtual void OnSelected (SqlDataSourceStatusEventArgs e)
839 if (!HasEvents ()) return;
840 SqlDataSourceStatusEventHandler h = Events [EventSelected] as SqlDataSourceStatusEventHandler;
845 public event SqlDataSourceStatusEventHandler Selected {
846 add { Events.AddHandler (EventSelected, value); }
847 remove { Events.RemoveHandler (EventSelected, value); }
850 static readonly object EventSelecting = new object ();
851 protected virtual void OnSelecting (SqlDataSourceSelectingEventArgs e)
853 if (!HasEvents ()) return;
854 SqlDataSourceSelectingEventHandler h = Events [EventSelecting] as SqlDataSourceSelectingEventHandler;
858 public event SqlDataSourceSelectingEventHandler Selecting {
859 add { Events.AddHandler (EventSelecting, value); }
860 remove { Events.RemoveHandler (EventSelecting, value); }
865 static readonly object EventUpdated = new object ();
866 protected virtual void OnUpdated (SqlDataSourceStatusEventArgs e)
868 if (owner.EnableCaching)
869 owner.Cache.Expire ();
871 if (!HasEvents ()) return;
872 SqlDataSourceStatusEventHandler h = Events [EventUpdated] as SqlDataSourceStatusEventHandler;
877 public event SqlDataSourceStatusEventHandler Updated {
878 add { Events.AddHandler (EventUpdated, value); }
879 remove { Events.RemoveHandler (EventUpdated, value); }
882 static readonly object EventUpdating = new object ();
883 protected virtual void OnUpdating (SqlDataSourceCommandEventArgs e)
885 if (!HasEvents ()) return;
886 SqlDataSourceCommandEventHandler h = Events [EventUpdating] as SqlDataSourceCommandEventHandler;
890 public event SqlDataSourceCommandEventHandler Updating {
891 add { Events.AddHandler (EventUpdating, value); }
892 remove { Events.RemoveHandler (EventUpdating, value); }