0

我一直在尝试添加页脚,以便它可以显示原始总金额的总销售额。

有人可以帮我,为什么我的页脚不显示?

我曾尝试从网上复制并将其放入 Gridview,但仍然失败。

任何人 ?谢谢你。

    <div id="div_print1">
           <%-- <asp:Panel runat="server" ID="pnlInvConfirm" GroupingText="CONFIRM"> --%>
            <asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center" ShowFooter="true" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False">
                <RowStyle HorizontalAlign="Center" />
                <AlternatingRowStyle HorizontalAlign="Center" />

            <columns>
            <asp:templatefield headertext="Invoice ID">
                  <itemtemplate>
                        <asp:Label ID="lblInvID" Text='<%# Eval("invID") %>' runat="server" /> 
                     </itemtemplate>
                    <ItemStyle HorizontalAlign="Center" />
                 </asp:templatefield>

                <asp:templatefield headertext="NRIC">
                  <itemtemplate>
                       <asp:Label ID="lblcusNRIC" runat="server" Text='<%#Eval("cusNRIC") %>'></asp:Label>
                     </itemtemplate>
                    <ItemStyle HorizontalAlign="Center" />
                 </asp:templatefield>

                 <asp:templatefield headertext="Name">
                  <itemtemplate>
                       <asp:Label ID="lblcusName" runat="server" Text='<%#Eval("cusName")%>'></asp:Label>
                     </itemtemplate>
                     <ItemStyle HorizontalAlign="Center" />
                 </asp:templatefield>

                <asp:templatefield headertext="Contact Number">
                  <itemtemplate>
                       <asp:Label ID="lblcusHP1" runat="server" Text='<%#Eval("cusHP1") %>'></asp:Label>
                     </itemtemplate>
                    <ItemStyle HorizontalAlign="Center" />
                 </asp:templatefield>

                <asp:templatefield headertext="Invoice Date">
                <itemtemplate>
                <asp:Label ID="lblinvDate" runat="server" Text='<%#Eval ("invDate","{0:yyyy-MM-dd}") %>'></asp:Label>
                </itemtemplate>
                </asp:templatefield>

                <asp:templatefield headertext="Last Updated Date">
                <itemtemplate>
                <asp:Label ID="lblinvLastUpdated" runat="server" Text='<%#Eval ("invLastUpdated","{0:yyyy-MM-dd}") %>'></asp:Label>
                </itemtemplate>
                </asp:templatefield>

                <asp:templatefield headertext="Deposit (RM)">
                  <itemtemplate>
                    <asp:Label ID="lblinvDeposit" runat="server" Text='<%#Eval("invDeposit") %>'></asp:Label>
                  </itemtemplate>
                    <ItemStyle HorizontalAlign="Center" />
                 </asp:templatefield>

                <asp:templatefield headertext="New Balance (RM)">
                  <itemtemplate> 
                    <asp:Label ID="lblinvNewBalance" runat="server" Text='<%#Eval("invNewBalance") %>'></asp:Label>
                  </itemtemplate>
                    <FooterTemplate>
                        <asp:Label ID="lblttlSales" runat="server" Text="Total Sales"></asp:Label>
                   </FooterTemplate>
                    <ItemStyle HorizontalAlign="Center" />
                 </asp:templatefield>

                <asp:templatefield headertext=" Original Total Amount (RM)">
                  <itemtemplate>
                       <asp:Label ID="lblinvGrandTotal" runat="server" Text='<%#Eval("invGrandTotal") %>'></asp:Label>
                     </itemtemplate>
                    <ItemStyle HorizontalAlign="Center" />
                     <FooterTemplate>
                        <asp:Label ID="lblTotalSales" runat="server" ></asp:Label>
                    </FooterTemplate>
                 </asp:templatefield>

            </columns>  
            </asp:GridView>
           <%-- </asp:Panel> --%>
            </div>

这是.cs代码:-

     protected void G1(string sValue)
{
    //pnlInvConfirm.Visible = true;
    string inv_Status = "Confirm";

    if (rdlSearchRep.Text == "All")
    {
        try
        {
            MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
            con.Open();

            //MySqlCommand cmd = new MySqlCommand("SELECT * FROM reportdetailsinv",con);

            MySqlCommand cmd = new MySqlCommand("SELECT * FROM reportdetailsinv WHERE invStatus='" + inv_Status + "' AND reportID LIKE ?search OR reportType LIKE ?search OR reportDate LIKE ?search OR cusNRIC LIKE ?search", con);

            cmd.Parameters.AddWithValue("@search", string.Format("%{0}%", txtSearchRep.Text));

            MySqlDataAdapter da = new MySqlDataAdapter(cmd);

            DataSet ds = new DataSet();
            da.Fill(ds, "reportdetailsinv");
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
            con.Close();
        }
        catch
        {

        }
    }
    else if (rdlSearchRep.Text == "Report ID")
    {
        try
        {
            MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
            con.Open();

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM reportdetailsinv WHERE invStatus='" + inv_Status + "' AND reportID='" + sValue + "'ORDER BY paymentDate ASC", con);

            DataSet ds = new DataSet();
            da.Fill(ds, "reportdetailsinv");
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
            con.Close();

        }
        catch
        {

        }
    }
    else if (rdlSearchRep.Text == "Report Type")
    {
        try
        {
            MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
            con.Open();

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM reportdetailsinv WHERE invStatus='" + inv_Status + "' AND reportType='" + sValue + "' ORDER BY reportID ASC", con);

            DataSet ds = new DataSet();
            da.Fill(ds, "reportdetails");
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
            con.Close();
        }
        catch
        {

        }
    }
    else if (rdlSearchRep.Text == "Report Date")
    {
        try
        {
            MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
            con.Open();

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM reportdetailsinv WHERE invStatus='" + inv_Status + "' AND reportDate='" + sValue + "'ORDER BY reportID ASC", con);

            DataSet ds = new DataSet();
            da.Fill(ds, "reportdetails");
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
            con.Close();
        }
        catch
        {

        }
    }

}

4

1 回答 1

0

在这里,您需要Text像绑定其他标签一样绑定 DataSource 中的一些计算属性 -

<FooterTemplate>
    <asp:Label ID="lblTotalSales" runat="server"
               Text='<%#Eval("TotalSalesProperty") %>'/>
</FooterTemplate>

或者

如果您的数据源中没有任何此类计算属性,则需要RowDataBound使用 GridView 挂钩事件并在那里访问您的标签和fill it by summing up all the sales.

这将使您开始 -在 GridView 的页脚中显示总计

于 2013-08-18T06:59:04.380 回答