2

おそらく、これは ASP.NET 開発者のチームによって作成されたエラーの 1 つです。

私はこのようにCelenganのデータモデルを作りました、 format ( ColumnName: Type ) :

Celengan
CelenganID: System.Int32 [PK]
..  // means other field
..  // means other field
TanggalPemberian: System.DateTime
TanggalPengembalian: System.DateTime
..

次に、1 つの GridView と EntityDataSource を作成して、GridView で非常に単純な CRUD アプリケーションを作成しました。これは、私のページ (Celengan.aspx) からの私の entitydatasource デザイン コードです。

<asp:EntityDataSource ID="CelenganEntityDataSource" runat="server" ConnectionString="name=SmatContext" DefaultContainerName="SmatContext" EnableFlattening="False" EntitySetName="Celengans" Include="Perusahaan" EnableDelete="True" EnableUpdate="True"></asp:EntityDataSource>

見て、私は2つのコマンドを有効にします: EnableDelete="True"、およびEnableUpdate="True"

そして、これは私の GridView 設計コードです:

<asp:GridView ID="CelenganGridView" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="5" DataKeyNames="CelenganID" DataSourceID="CelenganEntityDataSource" ShowHeaderWhenEmpty="True">
    <Columns>
        <asp:BoundField DataField="CelenganID" HeaderText="ID" ReadOnly="True" SortExpression="CelenganID" >
        <asp:TemplateField HeaderText="Tanggal Pemberian" SortExpression="TanggalPemberian">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TanggalPemberian", "{0:dd/MM/yyyy}") %>' Width="80px"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("TanggalPemberian", "{0:dd/MM/yyyy}") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Tanggal Pengembalian" SortExpression="TanggalPengembalian">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TanggalPengembalian", "{0:dd/MM/yyyy}") %>' Width="80px"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Bind("TanggalPengembalian", "{0:dd/MM/yyyy}") %>'></asp:Label>
            </ItemTemplate>
        <asp:TemplateField ShowHeader="False">
            <EditItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Update" Text="Save" ></asp:LinkButton>
                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" ></asp:LinkButton>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" ></asp:LinkButton>
                <asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Apakah celengan ini akan di hapus ?');"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

それは、私の国(インドネシア)が非標準の日時形式(dd/MM/yyyy)を使用しているため、バインディング関数を"{0:dd/MM/yyyy}"形式で変更したことです。

しかし、今大きな問題は、変更されたバインディング機能により、CelenganEntityDataSourceをクリックしようとしても更新できませんでしLinkButton1CommandName=Update

更新しようとすると、次のエラーメッセージが表示されます。

プロパティ 'TanggalPemberian' の設定中にエラーが発生しました: 'パラメータ 'TanggalPemberian' の値をタイプ 'System.DateTime' に変換できません。

ソース エラー:

現在の Web 要求の実行中に未処理の例外が生成されました。例外の発生元と場所に関する情報は、以下の例外スタック トレースを使用して特定できます。

スタックトレース :

[EntityDataSourceValidationException: Error while setting property 'TanggalPemberian': 'Cannot convert the value of parameter 'TanggalPemberian' to the type 'System.DateTime'.'.]
   System.Web.UI.WebControls.EntityDataSourceView.ConvertProperties(IDictionary values, PropertyDescriptorCollection propertyDescriptors, ParameterCollection referenceParameters, Dictionary`2 convertedValues) +74592
   System.Web.UI.WebControls.EntityDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +355
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +87
   System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1210
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +738
   System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +89
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +88
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9642610
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
4

0 に答える 0