1

我使用此查詢添加列。但我可以綁定EmployeeId,receptionist_name,date_of_sale,所以你能告訴我如何綁定網格視圖中的第4列以及如何填充網格視圖。在網格視圖根據SQL查詢

UPDATE:這裏是我使用的代碼:

<Columns> 
    <asp:BoundField HeaderText="Date" DataField="date_of_sale" /> 
    <asp:BoundField HeaderText="Employe Id" DataField="EmployeeId" /> 
    <asp:BoundField HeaderText="Receiptist Name" DataField="receptionist_name" /> 
    <asp:TemplateField HeaderText="No. of Prospectus Sale"> 
    <ItemTemplate> 
     <asp:Label ID="salecount" runat="server" 
      Text='<%# Eval("SaleCount") %>'></asp:Label> 
    </ItemTemplate> 
    </asp:TemplateField> 
</Columns> 
+0

它不工作... –

+0

+0

我不知道如何添加問題的HTML代碼 –

回答

2

列方法如下:

  1. 將您的查詢變更爲:

    select EmployeeId, receptionist_name, date_of_sale, count(date_of_sale) as Total from FrontOffice group By EmployeeId, receptionist_name, date_of_sale order by date_of_sale

  2. 更改你的GridView的代碼如下:

    Replace Eval("SaleCount") to Eval("Total")

+0

感謝它現在正在工作。 –

1

而不是改變整個代碼只是別名像count(date_of_sale) As SaleCount

<Colums> 
    <asp:BoundField HeaderText="Date" DataField="date_of_sale" /> 
    <asp:BoundField HeaderText="Employe Id" DataField="EmployeeId" /> 
    <asp:BoundField HeaderText="Receiptist Name" DataField="receptionist_name" /> 
    <asp:BoundField HeaderText="No. of Prospectus Sale" DataField="SaleCount" /> 
</Columns> 
+0

我想你沒有更改SQL腳本來計數(date_of_sale)作爲SaleCount。請更改並嘗試。 –

+0

感謝您的幫助。 –