所以我有點麻煩試圖弄清楚我在這裏做錯了什麼。 我會給你一個我一直在做的事情的基本概要。您是否缺少using指令或程序集引用。 Visual Studio WebDeveloper 2010
我正在創建Details和一行數據是一個布爾值,我們最初使用CheckBoxField,但現在我們要刪除它並使用Boolean(True或False更改爲Yes或No)。 因此,我刪除了CheckBowField,將DataField設置爲「Discontinued」,然後使用該代碼;
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class CustomFormatting_DetailsViewTemplateField : System.Web.UI.Page
{
protected string DisplayDiscontinuedAsYESorNO(bool discontinued)
{
if (discontinued)
return "YES";
else
return "NO";
}
}
進入我的頁面.aspx.cs,我想出這個錯誤
說明:此請求提供服務所需資源的編譯過程中出現錯誤。請查看以下具體的錯誤細節並適當修改您的源代碼。
編譯器錯誤消息:CS1061:「ASP.customformatting_detailsviewtemplatefield_aspx」不包含關於「DetailsView1_PageIndexChanging」和沒有擴展方法「DetailsView1_PageIndexChanging」接受類型「ASP.customformatting_detailsviewtemplatefield_aspx」的第一個參數的定義可以發現(你?缺少using指令或程序集引用)
源錯誤:
Line 3:
Line 4: <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
Line 5: <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
Line 6: DataKeyNames="ProductID" DataSourceID="ObjectDataSource1"
Line 7: onpageindexchanging="DetailsView1_PageIndexChanging">
最後,這裏是代碼我的DetailsView
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="ProductID" DataSourceID="ObjectDataSource1"
onpageindexchanging="DetailsView1_PageIndexChanging">
<Fields>
<asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />
<asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />
<asp:BoundField DataField="SupplierName" HeaderText="Supplier" ReadOnly="True" SortExpression="SupplierName" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty/Unit" SortExpression="QuantityPerUnit" />
<asp:TemplateField HeaderText="Price and Inventory">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>
<br />
<strong>(In Stock/On Order: </strong>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("UnitsInStock") %>'></asp:Label>
<strong>/</strong>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("UnitsOnOrder") %>'>
</asp:Label><strong>)</strong>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UnitPrice" HeaderText="Price" SortExpression="UnitPrice"
DataFormatString="{0:c}" Visible="False" />
<asp:BoundField DataField="UnitsIStock" HeaderText="Units In Stock" SortExpression="UnitsInStock"
Visible="False" />
<asp:BoundField DataField="UnitsOnOrder" HeaderText="Units On Order" SortExpression="UnitsOnOrder"
Visible="False" />
<asp:TemplateField HeaderText="Discontinued">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Discontinued") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Discontinued") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Discontinued") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
很抱歉,如果我已經發布了太多的代碼,我只是不太確定,你可能需要幫我搞清楚我的問題是什麼。我對這整個Visual Basic的東西還是新手。 非常感謝您的建議!