2013-08-18 37 views
0

我一直在嘗試添加頁腳,以便它可以顯示原始總金額的總銷售額。爲什麼我的頁腳不顯示在gridview中?

有人可以幫助我,爲什麼我的頁腳不顯示?

我試過從網上覆制並放到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

你的html沒有錯。請發佈您的cs代碼。 – Raghubar

+0

剛剛轉貼與CS代碼。 – Shilpesh

回答

0

在這裏,你需要一些計算的屬性綁定Text在你的數據源像你這樣的其他標籤 -

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

如果您的DataSource中沒有任何此類計算屬性,則需要使用GridView掛接到RowDataBound事件,並訪問您的標籤,然後訪問fill it by summing up all the sales

這會讓你開始 - Displaying Total in footer of GridView

相關問題