回答編集履歴
1
追記追加
test
CHANGED
@@ -73,3 +73,335 @@
|
|
73
73
|
|
74
74
|
|
75
75
|
どうしても CheckBox と Label を切り替えて表示したいということであれば、GridView の RowDataBound イベントのハンドラで処置するなどもう一工夫必要ですが、ASPX ページのコードの可読性は格段に上がるはずです。
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
**【追記】**
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
サンプルを作ったのでアップしておきます。Result クラスは上のものから簡略化しました。.aspx のコードで、GridView1 が文字列で表示、GridView2 が CheckBox と Label を切り替えて表示するようにしています。
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
**ビジネスロジック**
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
using System;
|
94
|
+
|
95
|
+
using System.Collections.Generic;
|
96
|
+
|
97
|
+
using System.Linq;
|
98
|
+
|
99
|
+
using System.Web;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
public class Result
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
public string Name { get; set; }
|
108
|
+
|
109
|
+
public string App1 { get; set; }
|
110
|
+
|
111
|
+
public string App2 { get; set; }
|
112
|
+
|
113
|
+
public string App3 { get; set; }
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
public class BusinessLogic
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
public List<Result> GetResults()
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
List<Result> results = new List<Result>()
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
new Result() { Name = "ユーザー1", App1 = "チェック未", App2 = "申請不可", App3 = "チェック未" },
|
132
|
+
|
133
|
+
new Result() { Name = "ユーザー2", App1 = "チェック済", App2 = "チェック未", App3 = "申請済" },
|
134
|
+
|
135
|
+
new Result() { Name = "ユーザー3", App1 = "チェック未", App2 = "チェック済", App3 = "チェック済" }
|
136
|
+
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
return results;
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
**.aspx**
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
<%@ Page Language="C#" AutoEventWireup="true"
|
160
|
+
|
161
|
+
CodeFile="0022-GridViewCheckBox.aspx.cs"
|
162
|
+
|
163
|
+
Inherits="_0022_GridViewCheckBox" %>
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
<!DOCTYPE html>
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
172
|
+
|
173
|
+
<head runat="server">
|
174
|
+
|
175
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
176
|
+
|
177
|
+
<title></title>
|
178
|
+
|
179
|
+
</head>
|
180
|
+
|
181
|
+
<body>
|
182
|
+
|
183
|
+
<form id="form1" runat="server">
|
184
|
+
|
185
|
+
<asp:ObjectDataSource ID="ObjectDataSource1"
|
186
|
+
|
187
|
+
runat="server" SelectMethod="GetResults"
|
188
|
+
|
189
|
+
TypeName="BusinessLogic">
|
190
|
+
|
191
|
+
</asp:ObjectDataSource>
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
<asp:GridView ID="GridView1" runat="server"
|
196
|
+
|
197
|
+
AutoGenerateColumns="False"
|
198
|
+
|
199
|
+
DataSourceID="ObjectDataSource1">
|
200
|
+
|
201
|
+
<Columns>
|
202
|
+
|
203
|
+
<asp:BoundField DataField="Name" HeaderText="ユーザー名" />
|
204
|
+
|
205
|
+
<asp:BoundField DataField="App1" HeaderText="申請項目1" />
|
206
|
+
|
207
|
+
<asp:BoundField DataField="App2" HeaderText="申請項目2" />
|
208
|
+
|
209
|
+
<asp:BoundField DataField="App3" HeaderText="申請項目3" />
|
210
|
+
|
211
|
+
</Columns>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
</asp:GridView>
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
<asp:GridView ID="GridView2" runat="server"
|
220
|
+
|
221
|
+
AutoGenerateColumns="False"
|
222
|
+
|
223
|
+
DataSourceID="ObjectDataSource1">
|
224
|
+
|
225
|
+
<Columns>
|
226
|
+
|
227
|
+
<asp:BoundField DataField="Name" HeaderText="ユーザー名" />
|
228
|
+
|
229
|
+
<asp:TemplateField HeaderText="申請項目1">
|
230
|
+
|
231
|
+
<ItemTemplate>
|
232
|
+
|
233
|
+
<asp:CheckBox ID="CheckBox1" runat="server"
|
234
|
+
|
235
|
+
Visible='<%# CheckBoxVisible((string)Eval("App1")) %>'
|
236
|
+
|
237
|
+
Checked='<%# IsChecked((string)Eval("App1")) %>' />
|
238
|
+
|
239
|
+
<asp:Label ID="Label1" runat="server" Text='<%# Eval("App1") %>'
|
240
|
+
|
241
|
+
Visible='<%# LabelVisible((string)Eval("App1")) %>'>
|
242
|
+
|
243
|
+
</asp:Label>
|
244
|
+
|
245
|
+
</ItemTemplate>
|
246
|
+
|
247
|
+
</asp:TemplateField>
|
248
|
+
|
249
|
+
<asp:TemplateField HeaderText="申請項目2">
|
250
|
+
|
251
|
+
<ItemTemplate>
|
252
|
+
|
253
|
+
<asp:CheckBox ID="CheckBox2" runat="server"
|
254
|
+
|
255
|
+
Visible='<%# CheckBoxVisible((string)Eval("App2")) %>'
|
256
|
+
|
257
|
+
Checked='<%# IsChecked((string)Eval("App2")) %>' />
|
258
|
+
|
259
|
+
<asp:Label ID="Label2" runat="server" Text='<%# Eval("App2") %>'
|
260
|
+
|
261
|
+
Visible='<%# LabelVisible((string)Eval("App2")) %>'>
|
262
|
+
|
263
|
+
</asp:Label>
|
264
|
+
|
265
|
+
</ItemTemplate>
|
266
|
+
|
267
|
+
</asp:TemplateField>
|
268
|
+
|
269
|
+
<asp:TemplateField HeaderText="申請項目3">
|
270
|
+
|
271
|
+
<ItemTemplate>
|
272
|
+
|
273
|
+
<asp:CheckBox ID="CheckBox3" runat="server"
|
274
|
+
|
275
|
+
Visible='<%# CheckBoxVisible((string)Eval("App3")) %>'
|
276
|
+
|
277
|
+
Checked='<%# IsChecked((string)Eval("App3")) %>' />
|
278
|
+
|
279
|
+
<asp:Label ID="Label3" runat="server" Text='<%# Eval("App3") %>'
|
280
|
+
|
281
|
+
Visible='<%# LabelVisible((string)Eval("App3")) %>'>
|
282
|
+
|
283
|
+
</asp:Label>
|
284
|
+
|
285
|
+
</ItemTemplate>
|
286
|
+
|
287
|
+
</asp:TemplateField>
|
288
|
+
|
289
|
+
</Columns>
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
</asp:GridView>
|
294
|
+
|
295
|
+
</form>
|
296
|
+
|
297
|
+
</body>
|
298
|
+
|
299
|
+
</html>
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
```
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
**.aspx.cs**
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
```
|
312
|
+
|
313
|
+
using System;
|
314
|
+
|
315
|
+
using System.Collections.Generic;
|
316
|
+
|
317
|
+
using System.Linq;
|
318
|
+
|
319
|
+
using System.Web;
|
320
|
+
|
321
|
+
using System.Web.UI;
|
322
|
+
|
323
|
+
using System.Web.UI.WebControls;
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
public partial class _0022_GridViewCheckBox : System.Web.UI.Page
|
328
|
+
|
329
|
+
{
|
330
|
+
|
331
|
+
protected void Page_Load(object sender, EventArgs e)
|
332
|
+
|
333
|
+
{
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
protected bool LabelVisible(string str)
|
342
|
+
|
343
|
+
{
|
344
|
+
|
345
|
+
if (str == "チェック未" || str == "チェック済")
|
346
|
+
|
347
|
+
{
|
348
|
+
|
349
|
+
return false;
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
return true;
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
protected bool CheckBoxVisible(string str)
|
360
|
+
|
361
|
+
{
|
362
|
+
|
363
|
+
if (str == "チェック未" || str == "チェック済")
|
364
|
+
|
365
|
+
{
|
366
|
+
|
367
|
+
return true;
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
return false;
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
protected bool IsChecked(string str)
|
378
|
+
|
379
|
+
{
|
380
|
+
|
381
|
+
if (str == "チェック未")
|
382
|
+
|
383
|
+
{
|
384
|
+
|
385
|
+
return false;
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
if (str == "チェック済")
|
392
|
+
|
393
|
+
{
|
394
|
+
|
395
|
+
return true;
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
return false;
|
402
|
+
|
403
|
+
}
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
```
|