所以我在试图弄清楚我在这里做错了什么时遇到了一些麻烦。我会给你一个关于我一直在做的事情的基本概述。
我正在创建一个详细信息,其中一行数据是布尔值,我们最初使用的是 CheckBoxField,但现在我们要删除它并使用布尔值(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 的东西还是很陌生。非常感谢您的建议!