2

ASP.NET Web サイトで学生の一般加重平均 (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");
}
4

1 に答える 1

4

これを試してください:
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();
}
于 2012-05-07T07:02:08.653 に答える