0

そのため、ここで何が間違っているのかを正確に把握しようとするのに少し苦労しています。私がこれまでに行ってきたことの基本的な概要を説明します。

Details を作成していますが、データの 1 行がブール値です。もともとは 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' の定義が含まれておらず、タイプ 'ASP.customformatting_detailsviewtemplatefield_aspx' の最初の引数を受け入れる拡張メソッド 'DetailsView1_PageIndexChanging' が見つかりませんでした (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 全体に慣れていません。アドバイスありがとうございます!

4

1 に答える 1

1

コントロールをDetailsViewaspx ページに配置し、マークアップでイベントの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.";
    }

}

ここを参照してください。

于 2013-04-12T06:52:13.063 に答える