浏览代码

* AutoGeneratedField.cs, CheckBoxField.cs: fixed OnDataBindField, should hide checkbox only if DataItem is not defined

svn path=/trunk/mcs/; revision=98048
Vladimir Krasnov 18 年之前
父节点
当前提交
797ac3dc31

+ 10 - 6
mcs/class/System.Web/System.Web.UI.WebControls/AutoGeneratedField.cs

@@ -117,14 +117,18 @@ namespace System.Web.UI.WebControls {
 			if (dataType == typeof(bool)) {
 				CheckBox box = (CheckBox) cell.Controls [0];
 				object val = GetValue (cell.BindingContainer);
-				if (val != null) {
+				if (val != null && val != DBNull.Value)
 					box.Checked = (bool)val;
-					if (!box.Visible)
-						box.Visible = true;
-				}
 				else
-					box.Visible = false;
-			} else
+					if (string.IsNullOrEmpty (DataField)) {
+						box.Visible = false;
+						return;
+					}
+				
+				if (!box.Visible)
+					box.Visible = true;
+			}
+			else
 				base.OnDataBindField (sender, e);
 		}
 		

+ 5 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,8 @@
+2008-03-12  Vladimir Krasnov  <[email protected]>
+
+	* AutoGeneratedField.cs, CheckBoxField.cs: fixed OnDataBindField,
+	should hide checkbox only if DataItem is not defined
+
 2008-03-09  Dean Brettle <[email protected]> 
 
 	* DetailsView.cs, ListControl.cs, DataBoundControl.cs, 

+ 8 - 5
mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxField.cs

@@ -124,13 +124,16 @@ namespace System.Web.UI.WebControls {
 				DataControlFieldCell cell = (DataControlFieldCell) sender;
 				CheckBox box = (CheckBox) cell.Controls [0];
 				object val = GetValue (cell.BindingContainer);
-				if (val != null) {
+				if (val != null && val != DBNull.Value)
 					box.Checked = (bool) val;
-					if (!box.Visible)
-						box.Visible = true;
-				}
 				else
-					box.Visible = false;
+					if (string.IsNullOrEmpty (DataField)) {
+						box.Visible = false;
+						return;
+					}
+
+				if (!box.Visible)
+					box.Visible = true;
 			}
 			catch (HttpException) {
 				throw;