我是全新的,以ASP和下載的購物車的一些示例代碼。當我在Visual Studio中創建一個新項目時,添加了所有文件並試圖編譯我得到以下錯誤。找不到GridView控件在ASP
錯誤1 'gvShoppingCart' 不會在目前情況下存在C的名字:\用戶\ slaphappysmoker \文檔\ Visual Studio 2010的\項目\的購物車\的購物車\ ViewCart.aspx.cs 21 3的購物車
但是我能看到gvShoppingCart在ViewCart.aspx文件被定義。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewCart.aspx.cs" Inherits="ViewCart" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Shopping Cart</title>
<link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h1>Shopping Cart</h1>
<a href="Default.aspx">< Back to Products</a>
<br /><br />
<asp:GridView runat="server" ID="gvShoppingCart" AutoGenerateColumns="false" EmptyDataText="There is nothing in your shopping cart." GridLines="None" Width="100%" CellPadding="5" ShowFooter="true" DataKeyNames="ProductId" OnRowDataBound="gvShoppingCart_RowDataBound" OnRowCommand="gvShoppingCart_RowCommand">
<HeaderStyle HorizontalAlign="Left" BackColor="#3D7169" ForeColor="#FFFFFF" />
<FooterStyle HorizontalAlign="Right" BackColor="#6C6B66" ForeColor="#FFFFFF" />
<AlternatingRowStyle BackColor="#F8F8F8" />
<Columns>
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox runat="server" ID="txtQuantity" Columns="5" Text='<%# Eval("Quantity") %>'></asp:TextBox><br />
<asp:LinkButton runat="server" ID="btnRemove" Text="Remove" CommandName="Remove" CommandArgument='<%# Eval("ProductId") %>' style="font-size:12px;"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UnitPrice" HeaderText="Price" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
<asp:BoundField DataField="TotalPrice" HeaderText="Total" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
</Columns>
</asp:GridView>
<br />
<asp:Button runat="server" ID="btnUpdateCart" Text="Update Cart" OnClick="btnUpdateCart_Click" />
</div>
</form>
</body>
</html>
這裏是正在調用的GridView在ViewCart.aspx.cs文件中的代碼:
protected void BindData() {
// Let's give the data to the GridView and let it work!
// The GridView will take our cart items one by one and use the properties
// that we declared as column names (DataFields)
gvShoppingCart.DataSource = ShoppingCart.Instance.Items;
gvShoppingCart.DataBind();
}
我怎樣才能獲得ViewCart.aspx.cs代碼文件識別ViewCart.aspx和GridView中包含的?
編輯:新增調用gridview的功能。
哪裏的代碼中找到,具體在哪些功能?有幾個函數在頁面加載時運行,有些在創建元素之前,一些在之後。 – 2011-03-26 23:12:36
任何重複的類名或重複的命名空間名? – paparush 2011-03-26 23:26:25
我看不到。來自編譯器的唯一錯誤是無法找到所有gvSHoppingCart。 – 2011-03-26 23:27:44