2012-12-06 77 views
0

在我的RowDataBound事件中,我想更新行值,但是我無法將我的對象轉換爲DataRowView。是否有另一種方式來更新行列?如何在沒有datarowview的情況下更新gridview行?

這是我的。它不能將類型提供轉換爲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

您能否顯示綁定代碼? (IE grdvOffers.DataSource = ????) – Steve

回答

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(); 
     } 
    } 
相關問題