|
 |
|
[SUM] ผมต้องการ Sum ค่าที่อยู่ใน Gridview ให้อยู่ใน Footer Row ครับ แต่ติดปัญหาค่าที่ออกมาเป็น 0 หมดเลยครับ |
|
 |
|
|
 |
 |
|
ขอดูโค้ด ASP ด้วย
|
 |
 |
 |
 |
Date :
2018-01-30 13:50:43 |
By :
OOP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอทั้ง Gridview เลย
|
 |
 |
 |
 |
Date :
2018-01-30 14:12:04 |
By :
OOP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 3 เขียนโดย : OOP เมื่อวันที่ 2018-01-30 14:12:04
รายละเอียดของการตอบ ::
Code (ASP)
<asp:GridView ID="myGridview" runat="server"
CssClass="table table-striped table-bordered"
AutoGenerateColumns="false"
ShowFooter="true"
DataKeyNames="duration_month"
OnRowCancelingEdit="modCancelCommand"
OnRowCommand="myGridview_RowCommand"
OnRowDeleting="modDeleteCommand"
OnRowEditing="modEditCommand"
OnRowUpdating="modUpdateCommand"
OnRowDataBound="myGridview_RowDataBound1">
<Columns>
<asp:TemplateField HeaderText="Action" ItemStyle-Width="10%">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" Text="" CommandArgument='' CommandName="Edit" ToolTip="Edit"><img src="../../assets/images/edit-file.png" /></asp:LinkButton>
<asp:LinkButton ID="lnkDelete" Visible="false" runat="server" Text="" CommandArgument='' CommandName="Delete" ToolTip="Delete" OnClientClick="return ConfirmDelete()"><img src="../../assets/images/delete-file.png" /></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" CommandArgument='' Text="" ValidationGroup="updateGrp" CommandName="Update" ToolTip="Save"><img src="../../assets/images/edit-file-success.png"/></asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CommandArgument='' Text="" CommandName="Cancel" ToolTip="Cancel"><img src="../../assets/images/edit-file-cancel.png" /></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration_ID" Visible="false">
<ItemTemplate>
<asp:Label ID="lbDurationID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.duration_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Month" ItemStyle-Width="30%">
<ItemTemplate>
<asp:Label ID="lbDurationmonth" runat="server" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.duration_month") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditDurationmonth" ReadOnly="true" Width="100%" class="form-control" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.duration_month") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lbtotalsum" runat="server" Text="Total Sum"></asp:Label>
<br />
<br />
<asp:Label ID="lbtotalaverage" runat="server" Text="Total Average"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration 0-1 year">
<ItemTemplate>
<asp:Label ID="lbDuration01y" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.duration_01y") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditDuration01y" ReadOnly="true" class="form-control" runat="server" onkeypress = "return functionx(event)" Text='<%# DataBinder.Eval(Container, "DataItem.duration_01y") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lbSum01" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="lbAve01" runat="server" Text="Average"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration 1-3 year">
<ItemTemplate>
<asp:Label ID="lbDuration13y" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.duration_13y") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditDuration13y" ReadOnly="true" class="form-control" runat="server" onkeypress = "return functionx(event)" Text='<%# DataBinder.Eval(Container, "DataItem.duration_13y") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lbSum13" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="lbAve13" runat="server" Text="Average"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration 3-6 year">
<ItemTemplate>
<asp:Label ID="lbDuration36y" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.duration_36y") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditDuration36y" ReadOnly="true" class="form-control" runat="server" onkeypress = "return functionx(event)" Text='<%# DataBinder.Eval(Container, "DataItem.duration_36y") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lbSum36" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="lbAve36" runat="server" Text="Average"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration 6-9 year">
<ItemTemplate>
<asp:Label ID="lbDuration69y" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.duration_69y") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditDuration69y" ReadOnly="true" class="form-control" runat="server" onkeypress = "return functionx(event)" Text='<%# DataBinder.Eval(Container, "DataItem.duration_69y") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lbSum69" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="lbAve69" runat="server" Text="Average"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration 9-12 year">
<ItemTemplate>
<asp:Label ID="lbDuration912y" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.duration_912y") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditDuration912y" ReadOnly="true" class="form-control" runat="server" onkeypress = "return functionx(event)" Text='<%# DataBinder.Eval(Container, "DataItem.duration_912y") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lbSum912" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="lbAve912" runat="server" Text="Average"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration 12year up">
<ItemTemplate>
<asp:Label ID="lbDuration12up" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.duration_12up") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditDuration12up" ReadOnly="true" class="form-control" runat="server" onkeypress = "return functionx(event)" Text='<%# DataBinder.Eval(Container, "DataItem.duration_12up") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lbSum12up" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="lbAve12up" runat="server" Text="Average"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Summary">
<ItemTemplate>
<asp:Label ID="lbSummary" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.total") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lbSumTotal" runat="server" Text="Sum"></asp:Label>
<br />
<br />
<asp:Label ID="lbAveTotal" runat="server" Text="Average"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
|
 |
 |
 |
 |
Date :
2018-01-30 14:15:35 |
By :
chetlove08 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
decimal totalSum13 = 0M;
decimal totalSum36 = 0M;
protected void myGridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
int totalItems = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label Sum13 = (Label)e.Row.FindControl("lbDuration13y");
Label Sum36 = (Label)e.Row.FindControl("lbDuration36y");
decimal year13 = Decimal.Parse(Sum13.Text);
decimal year36 = Decimal.Parse(Sum36.Text);
totalSum13 += year13;
totalSum36 += year36;
totalItems += 1;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbSum13 = (Label)e.Row.FindControl("lbSum13");
lbSum13.Text = totalSum13.ToString();
}
}
|
 |
 |
 |
 |
Date :
2018-01-30 15:04:11 |
By :
OOP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|