gpt4 book ai didi

asp.net ListView,在页脚中显示计算摘要?

转载 作者:行者123 更新时间:2023-12-04 18:21:54 25 4
gpt4 key购买 nike

我正在尝试在我的 ASP.NET 网站中计算学生的一般加权平均值 (GWA)

我的公式是(在 SQL 中)

ROUND(SUM((UnitsAcademic*Grade))/SUM(UnitsAcademic),3)

到目前为止,这是我的 ASP.NET。我想使用 ASP.NET 计算 GWA。现在我有点卡住了。

ASPX
<asp:ListView OnItemDataBound="listviewGrade_ItemDataBound" ID="listviewGrade" runat="server" DataSourceID="sqlGrade" DataKeyNames="GradebookDetailId">
<LayoutTemplate>
<table class="Container8" >
<tbody>
<tr>
<th>Subject Code</th>
<th>Description</th>
<th>Units</th>
<th>Grade</th>
<th>Remarks</th>
<th>Faculty Name</th>
</tr>
<tr id="itemPlaceholder" runat="server" />
</tbody>
</table>

</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("SubjectCode") %></td>
<td><%# Eval("Description") %></td>
<td><asp:Label ID="lblUnitsAcademic" runat="server" Text='<%# Eval("UnitsAcademic") %>' /></td>
<td><asp:Label ID="lblGrade" runat="server" Text='<%# Eval("Grade") %>' /></td>
<td><%# Eval("Remarks") %></td>
<td><%# Eval("FacultyName") %></td>
</tr>
</ItemTemplate>

</asp:ListView>
<br/>
<asp:Label ID="lblGWA" runat="server" />

C#
protected void listviewGrade_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Label lblGrade = (Label)e.Item.FindControl("lblGrade");
Label lblUnitsAcademic = (Label)e.Item.FindControl("lblUnitsAcademic");
}

最佳答案

尝试这个:
aspx:

<asp:ListView OnItemDataBound="listviewGrade_ItemDataBound" ID="listviewGrade" runat="server"
DataSourceID="sqlGrade" DataKeyNames="GradebookDetailId">
<LayoutTemplate>
<table class="Container8">
<tbody>
<tr>
<th>
Subject Code
</th>
<th>
Description
</th>
<th>
Units
</th>
<th>
Grade
</th>
<th>
Remarks
</th>
<th>
Faculty Name
</th>
</tr>
<tr id="itemPlaceholder" runat="server" />
</tbody>
<tfoot>
<asp:Label ID="lblSum" runat="server" Text="Label"></asp:Label>
</tfoot>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("SubjectCode") %>
</td>
<td>
<%# Eval("Description") %>
</td>
<td>
<asp:Label ID="lblUnitsAcademic" runat="server" Text='<%# Eval("UnitsAcademic") %>' />
</td>
<td>
<asp:Label ID="lblGrade" runat="server" Text='<%# Eval("Grade") %>' />
</td>
<td>
<%# Eval("Remarks") %>
</td>
<td>
<%# Eval("FacultyName") %>
</td>
</tr>
</ItemTemplate>
</asp:ListView>

CS:
int sum = 0;
protected void listviewGrade_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label lblGrade = (Label)e.Item.FindControl("lblGrade");
Label lblUnitsAcademic = (Label)e.Item.FindControl("lblUnitsAcademic");
sum += Convert.ToInt32(lblUnitsAcademic.Text) *
Convert.ToInt32(lblGrade.Text) / Convert.ToInt32(lblUnitsAcademic.Text);

}
}



protected void listviewGrade_LayoutCreated(object sender, EventArgs e)
{

Label lblSum = (Label)listviewGrade.FindControl("lblSum");
lblSum.Text = sum.ToString();
}

关于asp.net ListView,在页脚中显示计算摘要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10477549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com