我开发了asp.project,即时获取我的网格视图的sql表数据,没有显示任何错误,但没有在我的网格视图中显示数据,我该如何修复/
谢谢,
.aspx的
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div align="center">
<asp:Label ID="lblTitle" runat="server" Style="font-weight: 700">All Products</asp:Label>
<hr />
</div>
<table align="ceneter">
<tr><td align="cebter">
<asp:GridView ID="gvAvailableProducts" runat="server" Width="100%" AutoGenerateColumns="False" OnSelectedIndexChanged="gvAvailableProducts_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Name" ItemStyle-Width="150">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="CategoryName" HeaderText="ProductCategory" ItemStyle-Width="50">
<ItemStyle Width="50px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AvailableStock" HeaderText="AvailableStock" ItemStyle-Width="150" ItemStyle-Font-Bold="true" ItemStyle-Font-Size="Larger">
<ItemStyle Font-Bold="True" Font-Size="Larger" Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="ProductPrice" HeaderText="Price" ItemStyle-Width="150">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="ProductDescription" HeaderText="Description" ItemStyle-Width="150">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:ImageField DataAlternateTextField="ProductImage" ControlStyle-Width="150">
<ControlStyle Width="150px"></ControlStyle>
</asp:ImageField>
</Columns>
<RowStyle HorizontalAlign="Center" />
</asp:GridView>
</td></tr>
</table>
</asp:Content>
SP,
ALTER PROCEDURE [dbo].[SP_GetAllProdcuts](@CategoryID int)
AS
BEGIN
BEGIN TRY
IF (@CategoryID <> 0)
BEGIN
SELECT * FROM (SELECT
P.CategoryID,
p.ProductID,
p.ProductName,
p.ProductPrice,
p.ProductImage,
C.CategoryName,
p.ProductDescription,
p.ProductsQuantity,
Isnull (Sum(CP.TotalProducts),0) AS ProductSold,
(p.ProductsQuantity - Isnull (Sum(CP.TotalProducts),0)) AS AvailableStock
FROM Products P
INNER JOIN Category C
ON C.CategoryID = P.CategoryID
LEFT JOIN CustomerProducts CP
ON CP.ProductID = P.ProductID
GROUP BY
p.ProductID,
p.ProductName,
p.ProductPrice,
p.ProductImage,
C.CategoryName,
p.ProductDescription,
p.ProductsQuantity,
p.CategoryID) StockTable
WHERE AvailableStock > 0
AND CategoryID = @CategoryID
END
ELSE
BEGIN
SELECT * FROM (SELECT
P.CategoryID,
p.ProductID,
p.ProductName,
p.ProductPrice,
p.ProductImage,
C.CategoryName,
p.ProductDescription,
p.ProductsQuantity,
ISNULL (SUM(CP.TotalProducts),0) AS ProductSold,
(p.ProductsQuantity - isnull (sum(CP.TotalProducts),0)) AS AvailableStock
FROM Products P
INNER JOIN Category C
ON C.CategoryID = P.CategoryID
LEFT JOIN CustomerProducts CP
ON CP.ProductID = P.ProductID
GROUP BY
p.ProductID,
p.ProductName,
p.ProductPrice,
p.ProductImage,
C.CategoryName,
p.ProductDescription,
p.ProductsQuantity,
p.CategoryID) StockTable
WHERE AvailableStock > 0
AND CategoryID = @CategoryID
END
END TRY
BEGIN CATCH PRINT( '错误')
CATCH END
的.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetProducts(0); //Get All Products
}
}
private void GetProducts(int CategoryID)
{
ShoppingCart k = new ShoppingCart()
{
CategoryID = CategoryID
};
gvAvailableProducts.DataSource = null;
gvAvailableProducts.DataSource = k.GetAllProducts();
gvAvailableProducts.DataBind();
类文件
public DataTable GetAllProducts() {
SqlParameter[] parameters = new SqlParameter[1];
parameters[0] = DataLayer.DataAccess.AddParameter("@CategoryID", CategoryID, System.Data.SqlDbType.Int, 20);
DataTable dt = DataLayer.DataAccess.ExecuteDTByProcedure("SP_GetAllProdcuts", parameters);//Get All Record From SP
return dt;
}