System.Web.UI.WebControls.ListControl.PerformDataBinding C# (CSharp) Méthode

PerformDataBinding() protected méthode

protected PerformDataBinding ( IEnumerable dataSource ) : void
dataSource IEnumerable
Résultat void
		void PerformDataBinding (IEnumerable dataSource)
		{
			if (dataSource == null)
#if NET_2_0
				goto setselected;
#else
				return;
#endif
#if NET_2_0
			if (!AppendDataBoundItems)
#endif
				Items.Clear ();

			string format = DataTextFormatString;
			if (format.Length == 0)
				format = null;

			string text_field = DataTextField;
			string value_field = DataValueField;

			if (text_field.Length == 0)
				text_field = null;
			if (value_field.Length == 0)
				value_field = null;
			
			ListItemCollection coll = Items;
			foreach (object container in dataSource) {
				string text;
				string val;

				text = val = null;
				if (text_field != null)
					text = DataBinder.GetPropertyValue (container, text_field, format);
				
				if (value_field != null)
					val = DataBinder.GetPropertyValue (container, value_field).ToString ();
				else if (text_field == null) {
					text = val = container.ToString ();
					if (format != null)
						text = String.Format (format, container);
				} else if (text != null)
					val = text;

				if (text == null)
					text = val;

				coll.Add (new ListItem (text, val));
			}

#if NET_2_0
		setselected:
			if (!String.IsNullOrEmpty (_selectedValue)) {
				if (!SetSelectedValue (_selectedValue))
					throw new ArgumentOutOfRangeException ("value", String.Format ("'{0}' has a SelectedValue which is invalid because it does not exist in the list of items.", ID));
				if (_selectedIndex >= 0 && _selectedIndex != SelectedIndex)
					throw new ArgumentException ("SelectedIndex and SelectedValue are mutually exclusive.");
			}
			else if (_selectedIndex >= 0) {
				SelectedIndex = _selectedIndex;
			}
#else
			if (saved_selected_value != null) {
				SelectedValue = saved_selected_value;
				if (saved_selected_index != -2 && saved_selected_index != SelectedIndex)
					throw new ArgumentException ("SelectedIndex and SelectedValue are mutually exclusive.");
			}
			else if (saved_selected_index != -2) {
				SelectedIndex = saved_selected_index;
				// No need to check saved_selected_value here, as it's done before.
			}
#endif
		}