System.Web.UI.WebControls.CheckBoxList.LoadPostData C# (CSharp) Method

LoadPostData() protected method

protected LoadPostData ( string postDataKey, NameValueCollection postCollection ) : bool
postDataKey string
postCollection System.Collections.Specialized.NameValueCollection
return bool
		bool LoadPostData (string postDataKey, NameValueCollection postCollection)
		{
#if NET_2_0
			if (!IsEnabled)
				return false;
			EnsureDataBound ();
#else
			if (!Enabled)
				return false;
#endif
			int checkbox = -1;

			try {
				string id = postDataKey.Substring (ClientID.Length + 1);
				if (Char.IsDigit (id [0]))
					checkbox = Int32.Parse (id, Helpers.InvariantCulture);
			} catch {
				return false;
			}

			if (checkbox == -1)
				return false;

			string val = postCollection [postDataKey];
			bool ischecked = val == "on";
			ListItem item = Items [checkbox];
#if NET_2_0
			if (item.Enabled)
#endif
				if (ischecked && !item.Selected) {
					item.Selected = true;
					return true;
				} else if (!ischecked && item.Selected) {
					item.Selected = false;
					return true;
				}

			return false;
		}