Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EditCommandColumn.cs « System.Web.UI.WebControls « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1bc983f7c4080f976dcc87dcd99275841b64019f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
 * Namespace: System.Web.UI.WebControls
 * Class:     EditCommandColumn
 * 
 * Author:  Gaurav Vaish
 * Maintainer: gvaish@iitk.ac.in
 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
 * Implementation: yes
 * Status:  100%
 * 
 * (C) Gaurav Vaish (2002)
 */

using System;
using System.Web;
using System.Web.UI;

namespace System.Web.UI.WebControls
{
	public class EditCommandColumn : DataGridColumn
	{
		public EditCommandColumn(): base()
		{
		}
		
		public virtual ButtonColumnType ButtonType
		{
			get
			{
				object o = ViewState["ButtonType"];
				if(o != null)
				{
					return (ButtonColumnType)o;
				}
				return ButtonColumnType.LinkButton;
			}
			set
			{
				if(!Enum.IsDefined(typeof(ButtonColumnType), value))
				{
					throw new ArgumentException();
				}
				ViewState["ButtonType"] = value;
				OnColumnChanged();
			}
		}

		public virtual string CancelText
		{
			get
			{
				object o = ViewState["CancelText"];
				if(o != null)
				{
					return (string)o;
				}
				return String.Empty;
			}
			set
			{
				ViewState["CancelText"] = value;
				OnColumnChanged();
			}
		}

		public virtual string EditText
		{
			get
			{
				object o = ViewState["EditText"];
				if(o != null)
				{
					return (string)o;
				}
				return String.Empty;
			}
			set
			{
				ViewState["EditText"] = value;
				OnColumnChanged();
			}
		}

		public virtual string UpdateText
		{
			get
			{
				object o = ViewState["UpdateText"];
				if(o != null)
				{
					return (string)o;
				}
				return String.Empty;
			}
			set
			{
				ViewState["UpdateText"] = value;
				OnColumnChanged();
			}
		}
		
		public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)
		{
			base.InitializeCell(cell, columnIndex, itemType);
			
			if (itemType == ListItemType.Header || itemType == ListItemType.Footer)
				return;
			
			if (itemType == ListItemType.EditItem) {
				cell.Controls.Add (MakeButton ("Update", UpdateText));
				cell.Controls.Add (new LiteralControl ("&nbsp;"));
				cell.Controls.Add (MakeButton ("Cancel", CancelText));
			} else {
				cell.Controls.Add (MakeButton ("Edit", EditText));
			}
		}
		
		Control MakeButton (string commandName, string text)
		{
			if (ButtonType == ButtonColumnType.LinkButton) {
				DataGridLinkButton ret = new DataGridLinkButton ();
				ret.CommandName = commandName;
				ret.Text = text;
				return ret;
			} else {
				Button ret = new Button ();
				ret.CommandName = commandName;
				ret.Text = text;
				return ret;
			}
		}
	}
}