我一直在尝试添加页脚,以便显示原始总金额的总销售额。
有人可以帮助我,为什么我的页脚不显示?
我尝试从网上复制并将其放入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
{
}
}
}
答案 0 :(得分:0)
在这里,您需要将Text
与DataSource中的某些计算属性绑定,就像对其他标签所做的那样 -
<FooterTemplate>
<asp:Label ID="lblTotalSales" runat="server"
Text='<%#Eval("TotalSalesProperty") %>'/>
</FooterTemplate>
OR
如果您的DataSource中没有任何此类计算属性,则需要使用GridView挂钩RowDataBound
事件并在那里访问您的标签fill it by summing up all the sales
。
这会让你开始 - Displaying Total in footer of GridView。