回答編集履歴
1
追記
answer
CHANGED
@@ -3,4 +3,125 @@
|
|
3
3
|
GridView, ListView に合計表示
|
4
4
|
[http://surferonwww.info/BlogEngine/post/2010/11/07/Show-sum-in-GridView-or-ListView.aspx](http://surferonwww.info/BlogEngine/post/2010/11/07/Show-sum-in-GridView-or-ListView.aspx)
|
5
5
|
|
6
|
-
それがダメな理由があれば詳しく書いてください。
|
6
|
+
それがダメな理由があれば詳しく書いてください。
|
7
|
+
|
8
|
+
**【追記】**
|
9
|
+
|
10
|
+
下のコメントに「両方作って比較しないことには判断できないと思いますので、JavaScript / jQuery 案を回答欄に追記しておきます」と書きましたがそれを以下に書いておきます。
|
11
|
+
|
12
|
+
ベースは上の回答で紹介した記事のコードで、それに手を加えたものです。コードの下の方にあるの合計を計算して表示するスクリプトです。
|
13
|
+
|
14
|
+
|
15
|
+
```
|
16
|
+
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"
|
17
|
+
AutoEventWireup="true" CodeFile="0068-ListViewTotalByJavascript.aspx.cs"
|
18
|
+
Inherits="_0068_ListViewTotalByJavascript" %>
|
19
|
+
|
20
|
+
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
|
21
|
+
<style type="text/css">
|
22
|
+
table.style1
|
23
|
+
{
|
24
|
+
border-style: solid;
|
25
|
+
border-width: 2px;
|
26
|
+
border-color: Black;
|
27
|
+
text-align: center;
|
28
|
+
border-collapse: collapse;
|
29
|
+
}
|
30
|
+
|
31
|
+
table.style1 th
|
32
|
+
{
|
33
|
+
border-style: solid;
|
34
|
+
border-width: 2px 1px 2px 1px;
|
35
|
+
border-color: Black;
|
36
|
+
background-color: #6699FF;
|
37
|
+
color: #FFFFFF;
|
38
|
+
}
|
39
|
+
|
40
|
+
table.style1 td
|
41
|
+
{
|
42
|
+
border-style: solid;
|
43
|
+
border-width: 1px;
|
44
|
+
border-color: Black;
|
45
|
+
}
|
46
|
+
|
47
|
+
.footer
|
48
|
+
{
|
49
|
+
background-color: #CCFFFF;
|
50
|
+
}
|
51
|
+
</style>
|
52
|
+
|
53
|
+
</asp:Content>
|
54
|
+
|
55
|
+
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
|
56
|
+
<h3>Alfreds Futterkiste</h3>
|
57
|
+
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
|
58
|
+
ConnectionString="<%$ ConnectionStrings:NORTHWINDConnectionString %>"
|
59
|
+
SelectCommand="SELECT [OrderID], [OrderDate], [Freight]
|
60
|
+
FROM [Orders]
|
61
|
+
WHERE [CustomerID]='ALFKI'">
|
62
|
+
</asp:SqlDataSource>
|
63
|
+
<asp:ListView ID="ListView1"
|
64
|
+
runat="server"
|
65
|
+
DataKeyNames="OrderID"
|
66
|
+
DataSourceID="SqlDataSource1"
|
67
|
+
EnableModelValidation="True" >
|
68
|
+
<ItemTemplate>
|
69
|
+
<tr>
|
70
|
+
<td>
|
71
|
+
<asp:Label ID="OrderIDLabel"
|
72
|
+
runat="server"
|
73
|
+
Text='<%# Eval("OrderID") %>' />
|
74
|
+
</td>
|
75
|
+
<td>
|
76
|
+
<asp:Label ID="OrderDateLabel"
|
77
|
+
runat="server"
|
78
|
+
Text='<%# Eval("OrderDate", "{0:yyyy/MM/dd}") %>' />
|
79
|
+
</td>
|
80
|
+
<td>
|
81
|
+
<asp:TextBox ID="FreighTextBox"
|
82
|
+
runat="server"
|
83
|
+
Text='<%# Eval("Freight", "{0:N2}") %>' />
|
84
|
+
</td>
|
85
|
+
</tr>
|
86
|
+
</ItemTemplate>
|
87
|
+
<LayoutTemplate>
|
88
|
+
<table ID="itemPlaceholderContainer"
|
89
|
+
runat="server"
|
90
|
+
class="style1">
|
91
|
+
<tr runat="server">
|
92
|
+
<th runat="server">
|
93
|
+
OrderID</th>
|
94
|
+
<th runat="server">
|
95
|
+
OrderDate</th>
|
96
|
+
<th runat="server">
|
97
|
+
Freight</th>
|
98
|
+
</tr>
|
99
|
+
<tr ID="itemPlaceholder" runat="server">
|
100
|
+
</tr>
|
101
|
+
<tr class="footer">
|
102
|
+
<td></td>
|
103
|
+
<td>Freight Total</td>
|
104
|
+
<td>
|
105
|
+
<asp:TextBox ID="FreighTextBox"
|
106
|
+
runat="server" CssClass="total"/>
|
107
|
+
</td>
|
108
|
+
</tr>
|
109
|
+
</table>
|
110
|
+
</LayoutTemplate>
|
111
|
+
</asp:ListView>
|
112
|
+
|
113
|
+
<script type="text/javascript">
|
114
|
+
$(function () {
|
115
|
+
var sum = 0.0;
|
116
|
+
$('input:text').each(function () {
|
117
|
+
sum += Number($(this).val());
|
118
|
+
})
|
119
|
+
$('input.total').val(sum);
|
120
|
+
});
|
121
|
+
</script>
|
122
|
+
</asp:Content>
|
123
|
+
```
|
124
|
+
|
125
|
+
結果は以下のようになります。
|
126
|
+
|
127
|
+

|