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.
33 using System.Collections;
34 using System.Collections.Specialized;
37 using System.ComponentModel;
38 using System.Data.Common;
40 namespace System.Web.UI.WebControls {
41 public class SqlDataSourceView : DataSourceView, IStateManager {
44 DbProviderFactory factory;
45 DbConnection connection;
47 public SqlDataSourceView (SqlDataSource owner, string name, HttpContext context)
52 this.context = context;
55 void InitConnection ()
57 if (factory == null) factory = owner.GetDbProviderFactoryInternal ();
58 if (connection == null) {
59 connection = factory.CreateConnection ();
60 connection.ConnectionString = owner.ConnectionString;
64 public int Delete (IDictionary keys, IDictionary oldValues)
66 return ExecuteDelete (keys, oldValues);
69 protected override int ExecuteDelete (IDictionary keys, IDictionary oldValues)
72 throw new NotSupportedException("Delete operation is not supported");
73 if (oldValues == null && ConflictDetection == ConflictOptions.CompareAllValues)
74 throw new InvalidOperationException ("oldValues parameters should be specified when ConflictOptions is set to CompareAllValues");
78 DbCommand command = factory.CreateCommand ();
79 command.CommandText = DeleteCommand;
80 command.Connection = connection;
81 if (DeleteCommandType == SqlDataSourceCommandType.Text)
82 command.CommandType = CommandType.Text;
84 command.CommandType = CommandType.StoredProcedure;
86 IDictionary oldDataValues;
87 if (ConflictDetection == ConflictOptions.CompareAllValues) {
88 oldDataValues = new Hashtable ();
90 foreach (DictionaryEntry de in keys)
91 oldDataValues [de.Key] = de.Value;
93 if (oldValues != null) {
94 foreach (DictionaryEntry de in oldValues)
95 oldDataValues [de.Key] = de.Value;
101 InitializeParameters (command, DeleteParameters, null, oldDataValues, true);
103 SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
108 bool closed = connection.State == ConnectionState.Closed;
112 Exception exception = null;
115 result = command.ExecuteNonQuery();
116 } catch (Exception e) {
123 OnDataSourceViewChanged (EventArgs.Empty);
125 SqlDataSourceStatusEventArgs deletedArgs =
126 new SqlDataSourceStatusEventArgs (command, result, exception);
127 OnDeleted (deletedArgs);
129 if (exception != null && !deletedArgs.ExceptionHandled)
135 public int Insert (IDictionary values)
137 return ExecuteInsert (values);
140 protected override int ExecuteInsert (IDictionary values)
143 throw new NotSupportedException ("Insert operation is not supported");
147 DbCommand command = factory.CreateCommand ();
148 command.CommandText = InsertCommand;
149 command.Connection = connection;
150 if (InsertCommandType == SqlDataSourceCommandType.Text)
151 command.CommandType = CommandType.Text;
153 command.CommandType = CommandType.StoredProcedure;
155 InitializeParameters (command, InsertParameters, values, null, false);
157 SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
162 bool closed = connection.State == ConnectionState.Closed;
165 Exception exception = null;
168 result = command.ExecuteNonQuery ();
170 catch (Exception e) {
177 OnDataSourceViewChanged (EventArgs.Empty);
179 OnInserted (new SqlDataSourceStatusEventArgs (command, result, exception));
181 if (exception != null)
186 public IEnumerable Select (DataSourceSelectArguments arguments)
188 return ExecuteSelect (arguments);
191 protected internal override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
193 if (SortParameterName.Length > 0 && SelectCommandType == SqlDataSourceCommandType.Text)
194 throw new NotSupportedException ("The SortParameterName property is only supported with stored procedure commands in SqlDataSource");
196 if (arguments.SortExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
197 throw new NotSupportedException ("SqlDataSource cannot sort. Set DataSourceMode to DataSet to enable sorting.");
199 if (arguments.StartRowIndex > 0 || arguments.MaximumRows > 0)
200 throw new NotSupportedException ("SqlDataSource does not have paging enabled. Set the DataSourceMode to DataSet to enable paging.");
202 if (FilterExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
203 throw new NotSupportedException ("SqlDataSource only supports filtering when the data source's DataSourceMode is set to DataSet.");
207 DbCommand command = factory.CreateCommand ();
208 command.CommandText = SelectCommand;
209 command.Connection = connection;
210 if (SelectCommandType == SqlDataSourceCommandType.Text)
211 command.CommandType = CommandType.Text;
213 command.CommandType = CommandType.StoredProcedure;
214 if (SortParameterName.Length > 0 && arguments.SortExpression.Length > 0)
215 command.Parameters.Add (CreateDbParameter (SortParameterName, arguments.SortExpression));
218 if (SelectParameters.Count > 0)
219 InitializeParameters (command, SelectParameters, null, null, false);
221 Exception exception = null;
222 if (owner.DataSourceMode == SqlDataSourceMode.DataSet) {
223 DataView dataView = null;
225 if (owner.EnableCaching)
226 dataView = (DataView) owner.Cache.GetCachedObject (SelectCommand, SelectParameters);
228 if (dataView == null) {
229 SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
230 OnSelecting (selectingArgs);
231 if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
235 DbDataAdapter adapter = factory.CreateDataAdapter ();
236 DataSet dataset = new DataSet ();
238 adapter.SelectCommand = command;
239 adapter.Fill (dataset, name);
241 dataView = dataset.Tables [0].DefaultView;
242 if (dataView == null)
243 throw new InvalidOperationException ();
245 catch (Exception e) {
248 int rowsAffected = (dataView == null) ? 0 : dataView.Count;
249 SqlDataSourceStatusEventArgs selectedArgs = new SqlDataSourceStatusEventArgs (command, rowsAffected, exception);
250 OnSelected (selectedArgs);
252 if (exception != null && !selectedArgs.ExceptionHandled)
255 if (owner.EnableCaching)
256 owner.Cache.SetCachedObject (SelectCommand, selectParameters, dataView);
259 if (SortParameterName.Length == 0 || SelectCommandType == SqlDataSourceCommandType.Text)
260 dataView.Sort = arguments.SortExpression;
262 if (FilterExpression.Length > 0) {
263 IOrderedDictionary fparams = FilterParameters.GetValues (context, owner);
264 SqlDataSourceFilteringEventArgs fargs = new SqlDataSourceFilteringEventArgs (fparams);
267 object [] formatValues = new object [fparams.Count];
268 for (int n = 0; n < formatValues.Length; n++) {
269 formatValues [n] = fparams [n];
270 if (formatValues [n] == null) return dataView;
272 dataView.RowFilter = string.Format (FilterExpression, formatValues);
279 SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
280 OnSelecting (selectingArgs);
281 if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
285 DbDataReader reader = null;
286 bool closed = connection.State == ConnectionState.Closed;
291 reader = command.ExecuteReader (closed ? CommandBehavior.CloseConnection : CommandBehavior.Default);
293 catch (Exception e) {
296 int rows = reader == null ? 0 : reader.RecordsAffected;
297 SqlDataSourceStatusEventArgs selectedArgs = new SqlDataSourceStatusEventArgs (command, rows, exception);
298 OnSelected (selectedArgs);
299 if (exception != null && !selectedArgs.ExceptionHandled)
306 static bool PrepareNullParameters (DbCommand command, bool cancelIfHas)
308 for (int i = 0; i < command.Parameters.Count; i++) {
309 DbParameter param = command.Parameters [i];
310 if (param.Value == null && ((param.Direction & ParameterDirection.Input) != 0)) {
314 param.Value = DBNull.Value;
320 public int Update (IDictionary keys, IDictionary values, IDictionary oldValues)
322 return ExecuteUpdate (keys, values, oldValues);
325 protected override int ExecuteUpdate (IDictionary keys, IDictionary values, IDictionary oldValues)
328 throw new NotSupportedException ("Update operation is not supported");
329 if (oldValues == null && ConflictDetection == ConflictOptions.CompareAllValues)
330 throw new InvalidOperationException ("oldValues parameters should be specified when ConflictOptions is set to CompareAllValues");
334 DbCommand command = factory.CreateCommand ();
335 command.CommandText = UpdateCommand;
336 command.Connection = connection;
337 if (UpdateCommandType == SqlDataSourceCommandType.Text)
338 command.CommandType = CommandType.Text;
340 command.CommandType = CommandType.StoredProcedure;
342 IDictionary oldDataValues;
343 if (ConflictDetection == ConflictOptions.CompareAllValues) {
344 oldDataValues = new OrderedDictionary ();
346 foreach (DictionaryEntry de in keys)
347 oldDataValues [de.Key] = de.Value;
349 if (oldValues != null) {
350 foreach (DictionaryEntry de in oldValues)
351 oldDataValues [de.Key] = de.Value;
355 oldDataValues = keys;
358 IDictionary dataValues = values;
360 InitializeParameters (command, UpdateParameters, dataValues, oldDataValues, ConflictDetection == ConflictOptions.OverwriteChanges);
362 SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
367 bool closed = connection.State == ConnectionState.Closed;
370 Exception exception = null;
373 result = command.ExecuteNonQuery ();
375 catch (Exception e) {
382 OnDataSourceViewChanged (EventArgs.Empty);
384 SqlDataSourceStatusEventArgs updatedArgs =
385 new SqlDataSourceStatusEventArgs (command, result, exception);
386 OnUpdated (updatedArgs);
388 if (exception != null && !updatedArgs.ExceptionHandled)
394 string FormatOldParameter (string name)
396 string f = OldValuesParameterFormatString;
398 return String.Format (f, name);
403 object FindValueByName (string parameterName, IDictionary values, bool format)
408 foreach (DictionaryEntry de in values) {
409 string valueName = format == true ? FormatOldParameter (de.Key.ToString ()) : de.Key.ToString ();
410 if (String.Compare(parameterName, valueName, StringComparison.InvariantCultureIgnoreCase) == 0)
411 return values [de.Key];
416 void InitializeParameters (DbCommand command, ParameterCollection parameters, IDictionary values, IDictionary oldValues, bool parametersMayMatchOldValues)
418 IOrderedDictionary parameterValues = parameters.GetValues (context, owner);
420 foreach (string parameterName in parameterValues.Keys) {
421 Parameter p = parameters [parameterName];
422 object value = FindValueByName (parameterName, values, false);
423 string valueName = parameterName;
425 value = FindValueByName (parameterName, oldValues, true);
427 if (value == null && parametersMayMatchOldValues) {
428 value = FindValueByName (parameterName, oldValues, false);
429 valueName = FormatOldParameter (parameterName);
433 object dbValue = p.ConvertValue (value);
434 DbParameter newParameter = CreateDbParameter (valueName, dbValue, p.Direction, p.Size);
435 if (!command.Parameters.Contains (newParameter.ParameterName)) {
436 command.Parameters.Add (newParameter);
440 command.Parameters.Add (CreateDbParameter (p.Name, parameterValues [parameterName], p.Direction, p.Size));
444 if (values != null) {
445 foreach (DictionaryEntry de in values)
446 if (!command.Parameters.Contains (ParameterPrefix + (string) de.Key))
447 command.Parameters.Add (CreateDbParameter ((string) de.Key, de.Value));
450 if (oldValues != null) {
451 foreach (DictionaryEntry de in oldValues)
452 if (!command.Parameters.Contains (ParameterPrefix + FormatOldParameter ((string) de.Key)))
453 command.Parameters.Add (CreateDbParameter (FormatOldParameter ((string) de.Key), de.Value));
457 DbParameter CreateDbParameter (string name, object value)
459 return CreateDbParameter (name, value, ParameterDirection.Input, -1);
462 DbParameter CreateDbParameter (string name, object value, ParameterDirection dir, int size)
464 DbParameter dbp = factory.CreateParameter ();
465 dbp.ParameterName = ParameterPrefix + name;
474 void IStateManager.LoadViewState (object savedState)
476 LoadViewState (savedState);
479 object IStateManager.SaveViewState ()
481 return SaveViewState ();
484 void IStateManager.TrackViewState ()
489 NotSupportedException CreateNotSupportedException (string capabilityName)
491 return new NotSupportedException ("Data source does not have the '" + capabilityName + "' capability enabled.");
494 protected internal override void RaiseUnsupportedCapabilityError (DataSourceCapabilities capability)
496 if ((capability & DataSourceCapabilities.Sort) != 0 && !CanSort)
497 throw CreateNotSupportedException ("Sort");
499 if ((capability & DataSourceCapabilities.Page) != 0 && !CanPage)
500 throw CreateNotSupportedException ("Page");
502 if ((capability & DataSourceCapabilities.RetrieveTotalRowCount) != 0 && !CanRetrieveTotalRowCount)
503 throw CreateNotSupportedException ("RetrieveTotalRowCount");
506 protected virtual void LoadViewState (object savedState)
508 object [] vs = savedState as object [];
512 if (vs [0] != null) ((IStateManager) deleteParameters).LoadViewState (vs [0]);
513 if (vs [1] != null) ((IStateManager) filterParameters).LoadViewState (vs [1]);
514 if (vs [2] != null) ((IStateManager) insertParameters).LoadViewState (vs [2]);
515 if (vs [3] != null) ((IStateManager) selectParameters).LoadViewState (vs [3]);
516 if (vs [4] != null) ((IStateManager) updateParameters).LoadViewState (vs [4]);
519 protected virtual object SaveViewState ()
521 object [] vs = new object [5];
523 if (deleteParameters != null) vs [0] = ((IStateManager) deleteParameters).SaveViewState ();
524 if (filterParameters != null) vs [1] = ((IStateManager) filterParameters).SaveViewState ();
525 if (insertParameters != null) vs [2] = ((IStateManager) insertParameters).SaveViewState ();
526 if (selectParameters != null) vs [3] = ((IStateManager) selectParameters).SaveViewState ();
527 if (updateParameters != null) vs [4] = ((IStateManager) updateParameters).SaveViewState ();
529 foreach (object o in vs)
530 if (o != null) return vs;
534 protected virtual void TrackViewState ()
538 if (filterParameters != null) ((IStateManager) filterParameters).TrackViewState ();
539 if (selectParameters != null) ((IStateManager) selectParameters).TrackViewState ();
542 bool IStateManager.IsTrackingViewState {
543 get { return IsTrackingViewState; }
546 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
547 bool cancelSelectOnNullParameter = true;
548 public bool CancelSelectOnNullParameter {
549 get { return cancelSelectOnNullParameter; }
551 if (CancelSelectOnNullParameter == value)
553 cancelSelectOnNullParameter = value;
554 OnDataSourceViewChanged (EventArgs.Empty);
558 public override bool CanDelete {
559 get { return DeleteCommand != null && DeleteCommand != ""; }
562 public override bool CanInsert {
563 get { return InsertCommand != null && InsertCommand != ""; }
566 public override bool CanPage {
567 /* according to MS, this is false in all cases */
568 get { return false; }
571 public override bool CanRetrieveTotalRowCount {
572 /* according to MS, this is false in all cases */
573 get { return false; }
576 public override bool CanSort {
578 /* we can sort if we're a DataSet, regardless of sort parameter name.
579 we can sort if we're a DataReader, if the sort parameter name is not null/"".
581 return (owner.DataSourceMode == SqlDataSourceMode.DataSet
582 || (SortParameterName != null && SortParameterName != ""));
586 public override bool CanUpdate {
587 get { return UpdateCommand != null && UpdateCommand != ""; }
590 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
591 ConflictOptions conflictDetection = ConflictOptions.OverwriteChanges;
592 public ConflictOptions ConflictDetection {
593 get { return conflictDetection; }
595 if (ConflictDetection == value)
597 conflictDetection = value;
598 OnDataSourceViewChanged (EventArgs.Empty);
602 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
603 string deleteCommand = String.Empty;
604 public string DeleteCommand {
605 get { return deleteCommand; }
606 set { deleteCommand = value; }
609 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
610 SqlDataSourceCommandType deleteCommandType = SqlDataSourceCommandType.Text;
611 public SqlDataSourceCommandType DeleteCommandType {
612 get { return deleteCommandType; }
613 set { deleteCommandType = value; }
616 [DefaultValueAttribute (null)]
617 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
618 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
619 public ParameterCollection DeleteParameters {
620 get { return GetParameterCollection (ref deleteParameters, false, false); }
623 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
624 string filterExpression;
625 public string FilterExpression {
626 get { return filterExpression ?? string.Empty; }
628 if (FilterExpression == value)
630 filterExpression = value;
631 OnDataSourceViewChanged (EventArgs.Empty);
635 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
636 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
637 [DefaultValueAttribute (null)]
638 public ParameterCollection FilterParameters {
639 get { return GetParameterCollection (ref filterParameters, true, true); }
642 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
643 string insertCommand = String.Empty;
644 public string InsertCommand {
645 get { return insertCommand; }
646 set { insertCommand = value; }
649 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
650 SqlDataSourceCommandType insertCommandType = SqlDataSourceCommandType.Text;
651 public SqlDataSourceCommandType InsertCommandType {
652 get { return insertCommandType; }
653 set { insertCommandType = value; }
656 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
657 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
658 [DefaultValueAttribute (null)]
659 public ParameterCollection InsertParameters {
660 get { return GetParameterCollection (ref insertParameters, false, false); }
663 protected bool IsTrackingViewState {
664 get { return tracking; }
667 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
668 string oldValuesParameterFormatString = "{0}";
669 [DefaultValue ("{0}")]
670 public string OldValuesParameterFormatString {
671 get { return oldValuesParameterFormatString; }
673 if (OldValuesParameterFormatString == value)
675 oldValuesParameterFormatString = value;
676 OnDataSourceViewChanged (EventArgs.Empty);
680 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
681 string selectCommand;
682 public string SelectCommand {
683 get { return selectCommand != null ? selectCommand : string.Empty; }
685 if (SelectCommand == value)
687 selectCommand = value;
688 OnDataSourceViewChanged (EventArgs.Empty);
692 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
693 SqlDataSourceCommandType selectCommandType = SqlDataSourceCommandType.Text;
694 public SqlDataSourceCommandType SelectCommandType {
695 get { return selectCommandType; }
696 set { selectCommandType = value; }
699 public ParameterCollection SelectParameters {
700 get { return GetParameterCollection (ref selectParameters, true, true); }
703 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
704 string sortParameterName = String.Empty;
705 public string SortParameterName {
706 get { return sortParameterName; }
708 if (SortParameterName == value)
710 sortParameterName = value;
711 OnDataSourceViewChanged (EventArgs.Empty);
715 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
716 string updateCommand = String.Empty;
717 public string UpdateCommand {
718 get { return updateCommand; }
719 set { updateCommand = value; }
722 // LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
723 SqlDataSourceCommandType updateCommandType = SqlDataSourceCommandType.Text;
724 public SqlDataSourceCommandType UpdateCommandType {
725 get { return updateCommandType; }
726 set { updateCommandType = value; }
729 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
730 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
731 [DefaultValueAttribute (null)]
732 public ParameterCollection UpdateParameters {
733 get { return GetParameterCollection (ref updateParameters, false, false); }
736 void ParametersChanged (object source, EventArgs args)
738 OnDataSourceViewChanged (EventArgs.Empty);
741 ParameterCollection GetParameterCollection (ref ParameterCollection output, bool propagateTrackViewState, bool subscribeChanged)
746 output = new ParameterCollection ();
748 output.ParametersChanged += new EventHandler (ParametersChanged);
750 if (IsTrackingViewState && propagateTrackViewState)
751 ((IStateManager) output).TrackViewState ();
756 protected virtual string ParameterPrefix {
758 switch (owner.ProviderName) {
760 case "System.Data.SqlClient": return "@";
761 case "System.Data.OracleClient": return ":";
767 ParameterCollection deleteParameters;
768 ParameterCollection filterParameters;
769 ParameterCollection insertParameters;
770 ParameterCollection selectParameters;
771 ParameterCollection updateParameters;
779 static readonly object EventDeleted = new object ();
780 protected virtual void OnDeleted (SqlDataSourceStatusEventArgs e)
782 if (!HasEvents ()) return;
783 SqlDataSourceStatusEventHandler h = Events [EventDeleted] as SqlDataSourceStatusEventHandler;
788 public event SqlDataSourceStatusEventHandler Deleted {
789 add { Events.AddHandler (EventDeleted, value); }
790 remove { Events.RemoveHandler (EventDeleted, value); }
793 static readonly object EventDeleting = new object ();
794 protected virtual void OnDeleting (SqlDataSourceCommandEventArgs e)
796 if (!HasEvents ()) return;
797 SqlDataSourceCommandEventHandler h = Events [EventDeleting] as SqlDataSourceCommandEventHandler;
801 public event SqlDataSourceCommandEventHandler Deleting {
802 add { Events.AddHandler (EventDeleting, value); }
803 remove { Events.RemoveHandler (EventDeleting, value); }
808 static readonly object EventFiltering = new object ();
809 protected virtual void OnFiltering (SqlDataSourceFilteringEventArgs e)
811 if (!HasEvents ()) return;
812 SqlDataSourceFilteringEventHandler h = Events [EventFiltering] as SqlDataSourceFilteringEventHandler;
816 public event SqlDataSourceFilteringEventHandler Filtering {
817 add { Events.AddHandler (EventFiltering, value); }
818 remove { Events.RemoveHandler (EventFiltering, value); }
823 static readonly object EventInserted = new object ();
824 protected virtual void OnInserted (SqlDataSourceStatusEventArgs e)
826 if (!HasEvents ()) return;
827 SqlDataSourceStatusEventHandler h = Events [EventInserted] as SqlDataSourceStatusEventHandler;
832 public event SqlDataSourceStatusEventHandler Inserted {
833 add { Events.AddHandler (EventInserted, value); }
834 remove { Events.RemoveHandler (EventInserted, value); }
837 static readonly object EventInserting = new object ();
838 protected virtual void OnInserting (SqlDataSourceCommandEventArgs e)
840 if (!HasEvents ()) return;
841 SqlDataSourceCommandEventHandler h = Events [EventInserting] as SqlDataSourceCommandEventHandler;
845 public event SqlDataSourceCommandEventHandler Inserting {
846 add { Events.AddHandler (EventInserting, value); }
847 remove { Events.RemoveHandler (EventInserting, value); }
852 static readonly object EventSelected = new object ();
853 protected virtual void OnSelected (SqlDataSourceStatusEventArgs e)
855 if (!HasEvents ()) return;
856 SqlDataSourceStatusEventHandler h = Events [EventSelected] as SqlDataSourceStatusEventHandler;
861 public event SqlDataSourceStatusEventHandler Selected {
862 add { Events.AddHandler (EventSelected, value); }
863 remove { Events.RemoveHandler (EventSelected, value); }
866 static readonly object EventSelecting = new object ();
867 protected virtual void OnSelecting (SqlDataSourceSelectingEventArgs e)
869 if (!HasEvents ()) return;
870 SqlDataSourceSelectingEventHandler h = Events [EventSelecting] as SqlDataSourceSelectingEventHandler;
874 public event SqlDataSourceSelectingEventHandler Selecting {
875 add { Events.AddHandler (EventSelecting, value); }
876 remove { Events.RemoveHandler (EventSelecting, value); }
881 static readonly object EventUpdated = new object ();
882 protected virtual void OnUpdated (SqlDataSourceStatusEventArgs e)
884 if (owner.EnableCaching)
885 owner.Cache.Expire ();
887 if (!HasEvents ()) return;
888 SqlDataSourceStatusEventHandler h = Events [EventUpdated] as SqlDataSourceStatusEventHandler;
893 public event SqlDataSourceStatusEventHandler Updated {
894 add { Events.AddHandler (EventUpdated, value); }
895 remove { Events.RemoveHandler (EventUpdated, value); }
898 static readonly object EventUpdating = new object ();
899 protected virtual void OnUpdating (SqlDataSourceCommandEventArgs e)
901 if (!HasEvents ()) return;
902 SqlDataSourceCommandEventHandler h = Events [EventUpdating] as SqlDataSourceCommandEventHandler;
906 public event SqlDataSourceCommandEventHandler Updating {
907 add { Events.AddHandler (EventUpdating, value); }
908 remove { Events.RemoveHandler (EventUpdating, value); }