ASP.NET FormView OnItemUpdate - 未更新新值

时间:2015-08-03 12:58:31

标签: c# asp.net

我遇到事件OnItemUpdate ..在字典中的问题NewValues是旧值。怎么了?如何获得新价值?

<asp:FormView
    runat="server"
    ID="frvKartaCharakterystyk"
    RenderOuterTable="false"
    DefaultMode="Edit"
    OnItemUpdating="frvKartaCharakterystyk_ItemUpdating">
    <EditItemTemplate>
        <div class="form-horizontal">
            <div class="form-group">
                <label class="col-sm-3 control-label" for="inputProdukt">Produkt</label>
                <div class="col-sm-9">
                    <asp:TextBox runat="server" id="inputProdukt" CssClass="form-control" Text='<%# Bind("Produkt") %>' />
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-6 col-sm-3"><asp:LinkButton runat="server" CommandName="Update" type="button" class="btn btn-primary btn-lg btn-block">Zapisz</asp:LinkButton></div>
                <div class="col-sm-3"><asp:LinkButton runat="server" CommandName="Cancel" OnClick="Cancel_Click" type="button" class="btn btn-default btn-lg btn-block">Anuluj</asp:LinkButton></div>
            </div>
        </div>
    </EditItemTemplate>
</asp:FormView>

我的CodeBehind:

protected void frvKartaCharakterystyk_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        try
        {
            this.KartaCharakterystyk.Produkt = (string)e.NewValues["Produkt"];
            Response.Redirect("KartyCharakterystyk.aspx#record-" + (KartaCharakterystyk.Id - 1));
        }
        catch (Exception ex)
        {

        }
    }

1 个答案:

答案 0 :(得分:0)

问题出在Page_Load

this.frvKartaCharakterystyk.DataSource = new object[] { this.KartaCharakterystyk };
this.frvKartaCharakterystyk.DataBind();

更改为:

if (!IsPostBack)
{
    this.frvKartaCharakterystyk.DataSource = new object[] { this.KartaCharakterystyk };
    this.frvKartaCharakterystyk.DataBind();
}