* Parameter.cs:
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / ButtonColumn.cs
index 621ef07a58ac1440a539f83225b19cf619b8bae0..532ef1a675be2fc900f3ea4d0b1e15618d337e90 100755 (executable)
@@ -1,15 +1,13 @@
-/**\r
- * Namespace: System.Web.UI.WebControls\r
- * Class:     ButtonColumn\r
- * \r
- * Author:  Gaurav Vaish\r
- * Maintainer: gvaish@iitk.ac.in\r
- * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
- * Implementation: yes\r
- * Status:  20%\r
- * \r
- * (C) Gaurav Vaish (2001)\r
- */\r
+//
+// System.Web.UI.WebControls.ButtonColumn.cs
+//
+// Authors:
+//   Gaurav Vaish (gvaish@iitk.ac.in)
+//   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+//
+// (C) Gaurav Vaish (2002)
+// (C) 2003 Andreas Nahr
+//
 \r
 using System;\r
 using System.ComponentModel;\r
@@ -22,9 +20,8 @@ namespace System.Web.UI.WebControls
        {\r
                private PropertyDescriptor textFieldDescriptor;\r
                \r
-               public ButtonColumn()\r
+               public ButtonColumn(): base()\r
                {\r
-                       Initialize();\r
                }\r
 \r
                public override void Initialize()\r
@@ -33,14 +30,87 @@ namespace System.Web.UI.WebControls
                        textFieldDescriptor = null;\r
                }\r
                \r
-               [MonoTODO]\r
                public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)\r
                {\r
-                       InitializeCell(cell, columnIndex, itemType);\r
-                       //TODO: I also have to do some column specific work\r
-                       throw new NotImplementedException();\r
+                       base.InitializeCell(cell, columnIndex, itemType);\r
+                       if (Enum.IsDefined(typeof(ListItemType), itemType) &&\r
+                           itemType != ListItemType.Footer &&\r
+                           itemType != ListItemType.Header)\r
+                       {\r
+                               WebControl toDisplay = null;\r
+                               if(ButtonType == ButtonColumnType.PushButton)\r
+                               {\r
+                                       Button b = new Button();\r
+                                       b.Text = Text;\r
+                                       b.CommandName = CommandName;\r
+                                       b.CausesValidation = false;\r
+                                       toDisplay = b;\r
+                               } else\r
+                               {\r
+                                       LinkButton lb = new DataGridLinkButton();\r
+                                       lb.Text = Text;\r
+                                       lb.CommandName = CommandName;\r
+                                       lb.CausesValidation = false;\r
+                                       toDisplay = lb;\r
+                               }\r
+                               if(DataTextField.Length > 0)\r
+                               {\r
+                                       toDisplay.DataBinding += new EventHandler(OnDataBindButtonColumn);\r
+                               }\r
+                               cell.Controls.Add(toDisplay);\r
+                       }\r
+               }\r
+               \r
+               private void OnDataBindButtonColumn(object sender, EventArgs e)\r
+               {\r
+                       Control ctrl = (Control)sender;\r
+                       object item = ((DataGridItem)ctrl.NamingContainer).DataItem;\r
+                       if(textFieldDescriptor == null)\r
+                       {\r
+                               textFieldDescriptor = TypeDescriptor.GetProperties(item).Find(DataTextField, true);\r
+                               if(textFieldDescriptor == null && !DesignMode)\r
+                                       throw new HttpException(HttpRuntime.FormatResourceString("Field_Not_Found", DataTextField));\r
+                       }\r
+                       string text;\r
+                       if(textFieldDescriptor != null)\r
+                       {\r
+                               text = FormatDataTextValue(textFieldDescriptor.GetValue(item));\r
+                       } else\r
+                       {\r
+                               text = "Sample_DataBound_Text";\r
+                       }\r
+                       if(ctrl is LinkButton)\r
+                       {\r
+                               ((LinkButton)ctrl).Text = text;\r
+                       }\r
+                       else\r
+                       {\r
+                               ((Button)ctrl).Text = text;\r
+                       }\r
                }\r
                \r
+               protected virtual string FormatDataTextValue(object dataTextValue)\r
+               {\r
+                       string retVal = null;\r
+                       if(dataTextValue != null)\r
+                       {\r
+                               if(DataTextFormatString.Length > 0)\r
+                               {\r
+                                       retVal = String.Format(DataTextFormatString, dataTextValue);\r
+                               }\r
+                               else\r
+                               {\r
+                                       retVal = dataTextValue.ToString();\r
+                               }\r
+                       }\r
+                       return retVal;\r
+               }
+
+               // LAMESPEC The framework uses Description values for metadata here. However they should be WebSysDescriptions
+               // because all metadata in this namespace has WebSysDescriptions\r
+
+               [DefaultValue (typeof (ButtonColumnType), "LinkButton"), WebCategory ("Misc")]
+               [Description ("The type of button used in this column.")]\r
                public virtual ButtonColumnType ButtonType\r
                {\r
                        get\r
@@ -57,7 +127,9 @@ namespace System.Web.UI.WebControls
                                ViewState["ButtonType"] = value;\r
                        }\r
                }\r
-               \r
+
+               [DefaultValue (""), WebCategory ("Misc")]
+               [Description ("The command assigned to this column.")]\r
                public virtual string CommandName\r
                {\r
                        get\r
@@ -72,7 +144,9 @@ namespace System.Web.UI.WebControls
                                ViewState["CommandName"] = value;\r
                        }\r
                }\r
-\r
+
+               [DefaultValue (""), WebCategory ("Misc")]
+               [Description ("The datafield that is bound to the text property.")]\r
                public virtual string DataTextField\r
                {\r
                        get\r
@@ -87,7 +161,9 @@ namespace System.Web.UI.WebControls
                                ViewState["DataTextField"] = value;\r
                        }\r
                }\r
-\r
+
+               [DefaultValue (""), WebCategory ("Misc")]
+               [Description ("A format that is applied to the bound text property.")]\r
                public virtual string DataTextFormatString\r
                {\r
                        get\r
@@ -102,7 +178,9 @@ namespace System.Web.UI.WebControls
                                ViewState["DataTextFormatString"] = value;\r
                        }\r
                }\r
-\r
+
+               [DefaultValue (""), WebCategory ("Misc")]
+               [Description ("The text used for this button.")]\r
                public virtual string Text\r
                {\r
                        get\r
@@ -117,14 +195,5 @@ namespace System.Web.UI.WebControls
                                ViewState["Text"] = value;\r
                        }\r
                }\r
-               \r
-               [MonoTODO]\r
-               protected virtual string FormatDataTextValue(object dataTextValue)\r
-               {\r
-                       // TODO: The LOST WORLD! :))\r
-                       throw new NotImplementedException();\r
-                       return String.Empty;\r
-               }\r
-               \r
        }\r
 }\r