 |
|
ตอนนี้กำลังทำผลรวมใน grid view ค่ะ แต่เจอปัญหาผลรวมเบิ้ล *4 ครั้งค่ะ ทำให้ยอดที่แสดงไม่ถูกต้อง จึงรบกวนขอคำชี้แนะหน่อยค่ะว่าทำขั้นตอนใดผิด

ตอนนี้ที่ dtgdata_RowDataBound เขียนแบบนี้ค่ะ
Code
Protected Sub dtgdata_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles dtgdata.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
' Try
Dim lbltarget As Decimal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "e_target"))
Dim lblconfirm As Decimal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "e_planpack"))
totalltarget += lbltarget.ToString()
totalconfirm += lblconfirm.ToString()
' Catch ex As Exception
' End Try
End If
If e.Row.RowType = DataControlRowType.Footer Then
' Try
Dim lbltotaltarget As Label = DirectCast(e.Row.FindControl("lbltotaltarget"), Label)
lbltotaltarget.Text = totalltarget.ToString("N2")
Dim lbltotalconfirm As Label = DirectCast(e.Row.FindControl("lbltotalconfirm"), Label)
lbltotalconfirm.Text = totalconfirm.ToString("N2")
' Catch
' End Try
End If
End Sub
ส่วนที่ aspx
Code
<asp:GridView ID="dtgdata" runat="server" Width="99%" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" ShowFooter ="True" AllowPaging ="true" OnRowDataBound ="dtgdata_RowDataBound" GridLines ="Horizontal" >
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:TemplateField HeaderText="ECF">
<ItemTemplate><asp:Label ID="lbldept" runat="server" Text='<%# Eval("e_dept") %>' /></ItemTemplate>
<FooterTemplate><asp:Label ID="Label0" runat="server" /></FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="เป้าหมาย">
<ItemTemplate><asp:Label ID="lbltarget" runat="server" Text='<%# Eval("e_target", "{0:n}")%>' /></ItemTemplate>
<FooterTemplate><asp:Label ID="lbltotaltarget" runat="server" /></FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Confirm แพ็ค">
<ItemTemplate><asp:Label ID="lblconfirm" runat="server" Text='<%# Eval("e_planpack", "{0:n}")%>' /></ItemTemplate>
<FooterTemplate><asp:Label ID="lbltotalconfirm" runat="server" /></FooterTemplate>
</asp:TemplateField>
Tag : ASP, Ms SQL Server 2008, Web (ASP.NET), VB.NET, VS 2013 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2020-07-22 13:50:11 |
By :
nunan13 |
View :
980 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |