第一部分、Reteaper控件操作
在Repeater的FooterTemplate显示某列总计
Insus.NET练习一个小功能,在Repeater的FooterTemplate显示某列总计,参考下图最底Highlight一行。
【資料引用資訊】
google關鍵字:在Repeater的FooterTemplate显示某列总计
第二部分、Reteaper控件操作+資料庫資料
前端代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InspectProcessStepEight.aspx.cs" Inherits="AuditCertificationOperationSystem_MobileInspect_Inspect_InspectProcessStepEight" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>我要巡檢 (步驟8)</title>
</head>
<body>
<form runat="server">
<div>
<!-- Unnamed (表格) -->
<div id="u276" class="ax_default">
<asp:Repeater ID="rpAuditQuestionInfo1" runat="server" OnItemCommand="rpAuditQuestionInfo_ItemCommand">
<HeaderTemplate>
<div id="u248" class="css_table">
</HeaderTemplate>
<ItemTemplate>
<div class="css_tr">
<div class="css_td">
<asp:Label ID="Formid" runat="server" Text='<%#Eval("formid")%>' ></asp:Label>
</div>
<div class="css_td">
<asp:Label ID="AuditItem" class="ax_default table_cell text" runat="server" Text='<%#Eval("auditquestionnumber")%>' ></asp:Label>
</div>
<div class="css_td ">
<asp:Label ID="AuditQuestion" runat="server" Text='<%#Eval("question")%>'></asp:Label>
</div>
<div class="css_td">
<asp:TextBox ID="DateTimePicker" placeholder="請選擇時間" class="myDatePicker" runat="server"></asp:TextBox>
</div>
<div class="css_td">
<asp:TextBox ID="Remark" runat="server" placeholder="輸入檢測值"></asp:TextBox>
</div>
<div class="css_td">
<asp:Button ID="btnCheckY" class="html_button" runat="server" Text="是" CommandName="checkyes" CommandArgument='<%#Eval("qid") %>'/>
</div>
<div class="css_td">
<asp:Button ID="btnCheckN" class="html_button" runat="server" Text="否" CommandName="checkno" CommandArgument='<%#Eval("qid") %>'/>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
<div class="css_td"></div>
<div class="css_td"></div>
<div class="css_td">
<asp:Button ID="btnCheckAllY" class="html_button" name="btnCheckAllY" CommandName="checkallyes1" runat="server" Text="此步驟無缺失,點選後皆為是" />
</div>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="rpAuditQuestionInfo2" runat="server" OnItemCommand="rpAuditQuestionInfo_ItemCommand">
<HeaderTemplate>
<div id="u317" class="css_table">
</HeaderTemplate>
<ItemTemplate>
<div class="css_tr">
<div class="css_td">
<asp:Label ID="Formid" runat="server" Text='<%#Eval("formid")%>' ></asp:Label>
</div>
<div class="css_td">
<asp:Label ID="AuditItem" class="ax_default table_cell text" runat="server" Text='<%#Eval("auditquestionnumber")%>' ></asp:Label>
</div>
<div class="css_td ">
<asp:Label ID="AuditQuestion" runat="server" Text='<%#Eval("question")%>'></asp:Label>
</div>
<div class="css_td">
<asp:TextBox ID="DateTimePicker" placeholder="請選擇時間" class="myDatePicker" runat="server"></asp:TextBox>
</div>
<div class="css_td">
<asp:TextBox ID="Remark" runat="server" placeholder="輸入檢測值"></asp:TextBox>
</div>
<div class="css_td">
<asp:Button ID="btnCheckY" class="html_button" runat="server" Text="是" CommandName="checkyes" CommandArgument='<%#Eval("qid") %>'/>
</div>
<div class="css_td">
<asp:Button ID="btnCheckN" class="html_button" runat="server" Text="否" CommandName="checkno" CommandArgument='<%#Eval("qid") %>'/>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
<div class="css_td"></div>
<div class="css_td"></div>
<div class="css_td">
<asp:Button ID="btnCheckAllY" class="html_button" name="btnCheckAllY" CommandName="checkallyes2" runat="server" Text="此步驟無缺失,點選後皆為是" />
</div>
<div class="css_td">
<asp:Button ID="btnSentResoult" class="html_button" runat="server" Text="送出" OnClick="btnSentResoult_Click" />
</div>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
後臺代碼:
using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public partial class AuditCertificationOperationSystem_MobileInspect_Inspect_InspectProcessStepEight : System.Web.UI.Page
{
public DataTable questionanswercontent = new DataTable();
public Repeater rpAuditQuestionInfo = new Repeater();
protected void Page_Load(object sender, EventArgs e)
{
//產生表單
InitData("第一次檢測作業");
DataBind(rpAuditQuestionInfo1);
InitData("第二次檢測作業");
DataBind(rpAuditQuestionInfo2);
}
protected void InitData(string operationstate)
{
//產生空間存放題目相關資料-產生欄位
DataTable dt = new DataTable();
dt.Columns.Add("qid", typeof(string));
dt.Columns.Add("auditquestionnumber", typeof(string));
dt.Columns.Add("question", typeof(string));
dt.Columns.Add("formid", typeof(string));
//從資料庫抓取題庫資料
DataTable InspectQuestionData = InspectQuestionContent(operationstate);
//產生空間存放題目相關資料-放入資料
for (int i = 0; i < InspectQuestionData.Rows.Count; i++)
{
DataRow dr = dt.NewRow();
dr["qid"] = InspectQuestionData.Rows[i]["qid"].ToString();
dr["auditquestionnumber"] = InspectQuestionData.Rows[i]["auditquestionnumber"].ToString();
dr["question"] = InspectQuestionData.Rows[i]["question"].ToString();
dr["formid"] = "0";
dt.Rows.Add(dr);
}
ViewState.Add("AuditData", dt);
}
public void DataBind(Repeater rpauditquestioninfo)
{
rpauditquestioninfo.DataSource = ViewState["AuditData"] as DataTable;
rpauditquestioninfo.DataBind();
}
public static DataTable InspectQuestionContent(string operationstate)
{
string sql = string.Format(@" select * from AuditQuestion where audititemcode=8 and audititem='{0}'",
operationstate
);
return pDBClass.getDataTable(sql, DB_Act.ConnStr_DBN);
}
其他省略......
}
沒有留言:
張貼留言