在我的 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>
我想通了。您可以修改对象并将其重新设置并对其进行数据绑定。下面显示了如何操作。
/// <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();
}
}