---------------------------------------------------- GridView 利用 <asp:BoundField 計算總合;並在頁面不展現----------------------------------------------------
<asp:GridView ID="ReportView" runat="server" AutoGenerateColumns="False" GridLines="None" OnRowDataBound="ReportView_RowDataBound" ShowFooter="True" OnRowCreated="ReportView_RowCreated">
<Columns>
<asp:BoundField DataField="SN" HeaderText="sssssssssss"/>
<asp:BoundField DataField="RegName" HeaderText="sssssssss" />
<asp:TemplateField HeaderText="sssssss">
<ItemTemplate><%# Convert.ToDateTime(Eval("BeginTime")).ToString("yyyy-MM-dd HH:mm")%></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="eeee">
<ItemTemplate><%# Convert.ToDateTime(Eval("EndTime")).ToString("yyyy-MM-dd HH:mm")%></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NormalOverTotalTime" HeaderText="aaaaaa" />
<%-- <asp:TemplateField HeaderText="ccccc">
<ItemTemplate><%#Eval("NormalOverTotalTime").ToString() == "" ? "0" : Eval("NormalOverTotalTime").ToString()%>分鐘</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="cccccc">
<ItemTemplate><a href="Detail.aspx?ObjID=<%# Server.UrlEncode(Eval("ObjID").ToString())%>&ddate=<%# Server.UrlEncode(this.dDate.Value.ToString())%>&edate=<%# Server.UrlEncode(this.eDate.Value.ToString())%>&rtype=0" target="_blank"><%#Eval("NormalOverDegree").ToString()
== "" ? "0" : Eval("NormalOverDegree").ToString()%></a></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="HighOverTotalTime" HeaderText="ccccccccccc" />
<%--<asp:TemplateField HeaderText="ccccccccccc">
<ItemTemplate><%#Eval("HighOverTotalTime").ToString() == "" ? "0" : Eval("HighOverTotalTime").ToString()%>分鐘</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="sdssssss">
<ItemTemplate><a href="Detail.aspx?ObjID=<%# Server.UrlEncode(Eval("ObjID").ToString())%>&ddate=<%# Server.UrlEncode(this.dDate.Value.ToString())%>&edate=<%# Server.UrlEncode(this.eDate.Value.ToString())%>&rtype=1" target="_blank"><%#Eval("HighOverDegree").ToString()
== "" ? "0" : Eval("HighOverDegree").ToString()%></a></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NormalOverDegree" HeaderText="">
<ItemStyle Width="0px" />
</asp:BoundField>
<asp:BoundField DataField="HighOverDegree" HeaderText=""/>
</Columns>
<RowStyle CssClass="tr1" />
<AlternatingRowStyle CssClass="tr0" />
</asp:GridView>
public int TotalNormalOverTotalTime = 0;
public int TotalNormalOverDegree = 0;
public int TotalHighOverTotalTime = 0;
public int TotalHighOverDegree = 0;
//先利用列計算值;
protected void ReportView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
if (!"".Equals(e.Row.Cells[4].Text) && !" ".Equals(e.Row.Cells[4].Text))
{
TotalNormalOverTotalTime += Convert.ToInt32(e.Row.Cells[4].Text);
}
if (!"".Equals(e.Row.Cells[6].Text) && !" ".Equals(e.Row.Cells[6].Text))
{
TotalHighOverTotalTime += Convert.ToInt32(e.Row.Cells[6].Text);
}
if (!"".Equals(e.Row.Cells[8].Text) && !" ".Equals(e.Row.Cells[8].Text))
{
TotalNormalOverDegree += Convert.ToInt32(e.Row.Cells[8].Text);
}
if (!"".Equals(e.Row.Cells[9].Text) && !" ".Equals(e.Row.Cells[9].Text))
{
TotalHighOverDegree += Convert.ToInt32(e.Row.Cells[9].Text);
}
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = "合 計:";
e.Row.Cells[4].Text = TotalNormalOverTotalTime.ToString();
e.Row.Cells[5].Text = TotalNormalOverDegree.ToString();
e.Row.Cells[6].Text = TotalHighOverTotalTime.ToString();
e.Row.Cells[7].Text = TotalHighOverDegree.ToString();
}
}
//隱藏不顯示的列;
protected void ReportView_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[8].Visible = false;
e.Row.Cells[9].Visible = false;
}
}
GridView 利用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.