为什么我的页脚没有显示在网格视图中

本文关键字:网格 视图 显示 我的 为什么 | 更新日期: 2023-09-27 18:28:00

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

有人能帮我一下吗?为什么我的页脚没有显示出来?

我尝试过从网上复制并将其放入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
        {
        }
    }

}

为什么我的页脚没有显示在网格视图中

这里,您需要将Text与DataSource中的一些计算属性绑定,就像您对其他标签所做的那样-

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

如果DataSource中没有任何这样的计算属性,则需要使用GridView挂接到RowDataBound事件,并访问那里的标签和fill it by summing up all the sales

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