hello,
i have a Listview and i want to sum/total one of the column inside the Listview and here is my code.
<asp:ListView ID="ListView1" runat="server" DataKeyNames="AutoNum" DataSourceID="SqlDataSource1" InsertItemPosition="FirstItem">
<AlternatingItemTemplate>
<tr style="background-color:#FFF8DC;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="AutoNumLabel" runat="server" Text='<%# Eval("AutoNum") %>' />
</td>
<td>
<asp:Label ID="TermIDLabel" runat="server" Text='<%# Eval("TermID") %>' />
</td>
<td>
<asp:Label ID="GradingTypeLabel" runat="server" Text='<%# Eval("GradingType") %>' width="220px"/>
</td>
<td>
<asp:Label ID="GradingDescriptionLabel" runat="server" Text='<%# Eval("GradingDescription") %>' width="220px"/>
</td>
<td>
<asp:Label ID="GradingPointsLabel" runat="server" Text='<%# Eval("GradingPoints") %>' width="220px"/>
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="background-color:#008A8C;color: #FFFFFF;">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="AutoNumLabel1" runat="server" Text='<%# Eval("AutoNum") %>' />
</td>
<td>
<asp:TextBox ID="TermIDTextBox" runat="server" Text='<%# Bind("TermID") %>' />
</td>
<td>
<asp:TextBox ID="GradingTypeTextBox" runat="server" Text='<%# Bind("GradingType") %>' width="220px"/>
</td>
<td>
<asp:TextBox ID="GradingDescriptionTextBox" runat="server" Text='<%# Bind("GradingDescription") %>' width="220px"/>
</td>
<td>
<asp:TextBox ID="GradingPointsTextBox" runat="server" Text='<%# Bind("GradingPoints") %>' width="220px"/>
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td> </td>
<td>
<asp:DropDownList ID="DropDownList1" Width="80px" runat="server" DataSourceID="SqlDataSource2" DataTextField="TermID" DataValueField="TermID" SelectedValue='<%# Bind("TermID")%>'></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DBHUSRConnectionString %>" SelectCommand="QTermID_sp" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<%--<asp:TextBox ID="TermIDTextBox" runat="server" Text='<%# Bind("TermID") %>' />--%>
</td>
<td>
<asp:TextBox ID="GradingTypeTextBox" runat="server" Text='<%# Bind("GradingType") %>' width="220px"/>
</td>
<td>
<asp:TextBox ID="GradingDescriptionTextBox" runat="server" Text='<%# Bind("GradingDescription") %>' width="220px" />
</td>
<td>
<asp:TextBox ID="GradingPointsTextBox" runat="server" Text='<%# Bind("GradingPoints") %>' width="220px" />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="AutoNumLabel" runat="server" Text='<%# Eval("AutoNum") %>' />
</td>
<td>
<asp:Label ID="TermIDLabel" runat="server" Text='<%# Eval("TermID") %>' />
</td>
<td>
<asp:Label ID="GradingTypeLabel" runat="server" Text='<%# Eval("GradingType") %>' />
</td>
<td>
<asp:Label ID="GradingDescriptionLabel" runat="server" Text='<%# Eval("GradingDescription") %>' />
</td>
<td>
<asp:Label ID="GradingPointsLabel" runat="server" Text='<%# Eval("GradingPoints") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr runat="server" style="background-color:#DCDCDC;color: #000000;">
<th runat="server"></th>
<th runat="server">Num</th>
<th runat="server">Term</th>
<th runat="server">Type</th>
<th runat="server">Description</th>
<th runat="server">Points Possible or <br>% Total Grade</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;"></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="AutoNumLabel" runat="server" Text='<%# Eval("AutoNum") %>' />
</td>
<td>
<asp:Label ID="TermIDLabel" runat="server" Text='<%# Eval("TermID") %>' />
</td>
<td>
<asp:Label ID="GradingTypeLabel" runat="server" Text='<%# Eval("GradingType") %>' />
</td>
<td>
<asp:Label ID="GradingDescriptionLabel" runat="server" Text='<%# Eval("GradingDescription") %>' />
</td>
<td>
<asp:Label ID="GradingPointsLabel" runat="server" Text='<%# Eval("GradingPoints") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<br />
Total:<asp:Label ID="Label88" runat="server" Text="0"></asp:Label>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn() {New System.Data.DataColumn("GradingPoints", GetType(Integer))})
dt.Rows.Add(1)
'dt.Rows.Add(2)
'dt.Rows.Add(3)
Me.ListView1.DataSource = dt
Me.ListView1.DataBind()
End If
End Sub
please help.
thank you.