0

在我的 RowDataBound 事件中,我想更新行值,但我无法将我的对象转换为 DataRowView。还有另一种方法来更新行列吗?

这就是我所拥有的。它不能将类型 Offer 转换为 DataRowView。

 /// <summary>
    /// Gridview Row Data Bound 
    /// </summary>
    protected void grdvOffers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // Converts the UTC date to PST timezone
        if (e.Row.RowType == DataControlRowType.DataRow)
        {            

            //DataRow row = ((DataRowView)e.Row.DataItem).Row;
            Offer row = ((Offer)e.Row.DataItem).Row;
            DateTime utcTime = row.Field<DateTime>("Created");
            DateTime dtUpdateDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, CFrmFunctions.GetPresetTimeZone());
            row.SetField<DateTime>("Created", dtUpdateDateTime);
        }
    }


 <asp:ObjectDataSource ID="objOfferDataSource" runat="server" SelectMethod="GetAllOffers"
        TypeName="CancelForms.Repositories.OfferRepo"></asp:ObjectDataSource>
4

1 回答 1

0

我想到了。您可以修改对象并将其设置回来并进行数据绑定。下面展示了如何。

  /// <summary>
    /// Gridview Row Data Bound 
    /// </summary>
    protected void grdvOffers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // Converts the UTC date to PST timezone
        if (e.Row.RowType == DataControlRowType.DataRow)
        {  
            Offer offer = ((Offer)e.Row.DataItem);
            offer.Created = TimeZoneInfo.ConvertTimeFromUtc(offer.Created, CFrmFunctions.GetPresetTimeZone());
            e.Row.DataItem = offer;
            e.Row.DataBind();
        }
    }
于 2012-12-06T22:32:00.457 回答