在我的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>
答案 0 :(得分: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();
}
}