Domanda

In my RowDataBound event I would like to update the row values, but I can't convert my object to a DataRowView. Is there another way to update the row columns?

Here's what I have. It can't convert type Offer to 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>
È stato utile?

Soluzione

I figured it out. You can just modiy the object and set it back and databind it. Below shows how.

  /// <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();
        }
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top