gridview 顯示查無資料

  • 504
  • 0

以下是客制方式

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True" >
            <Columns>
                <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
                <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
                <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
            </Columns>
            <EmptyDataTemplate>
                <table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
        <tr>
            <th scope="col">ProductName</th><th scope="col">UnitPrice</th><th scope="col">Quantity</th>
        </tr>
        <tr><td colspan="3">查無任何資料</td></tr>
                    </table>
            </EmptyDataTemplate>
            <EmptyDataRowStyle ForeColor="Red" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>" SelectCommand="SELECT B.ProductName,A.UnitPrice,A.Quantity 
  FROM [dbo].[Order Details] A 
  LEFT JOIN  [dbo].[Products] B
  ON A.ProductID = B.ProductID  WHERE A.UnitPrice = 0
"></asp:SqlDataSource>