您是否缺少using指令或程序集引用。 Visual Studio WebDeveloper 2010

时间:2013-04-12 06:44:57

标签: c# visual-studio-2010 visual-web-developer-2010

所以我在试图找出我在这里做错了什么时遇到了一些麻烦。 我会告诉你我一直在做的事情。

我正在创建一个详细信息,并且一行数据是布尔值,我们最初使用的是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的新手。 非常感谢您的建议!

1 个答案:

答案 0 :(得分:1)

您的aspx页面中放置了DetailsView控件,并且在您的标记中,您声明将有onpageindexchanging事件的事件处理程序,但您未在代码中提供实现 - 后面。

来自MSDN的示例

protected void CustomerDetailView_PageIndexChanging(
  object sender, DetailsViewPageEventArgs e)
{
    // Cancel the paging operation if the user tries to 
    // navigate to another record while in edit mode.
    if (CustomerDetailView.CurrentMode == DetailsViewMode.Edit)
    {
        e.Cancel = true;
        // Display an error message.
        ErrorMessageLabel.Text = 
          "You cannot navigate to another record while in edit mode.";
    }

}

请参阅here