How to refresh ASPxGridView from database after edit

Bomberlt picture Bomberlt · Jul 20, 2012 · Viewed 9.4k times · Source

I have ASPxGridView:

<dx:ASPxGridView ID="ASPxGridView_Main" runat="server" ClientIDMode="AutoID" ClientInstanceName="gridMain" EnableRowsCache="False" Width="100%"  OnCellEditorInitialize="ASPxGridView_Main_CellEditorInitialize"  OnRowUpdated="ASPxGridView_Main_RowUpdated" OnHtmlDataCellPrepared="ASPxGridView_Main_HtmlDataCellPrepared" OnRowUpdating="ASPxGridView_Main_RowUpdating">
    <SettingsBehavior AllowFocusedRow="True" ColumnResizeMode="Control" EnableRowHotTrack="True" AllowClientEventsOnLoad="False"></SettingsBehavior>
    <SettingsEditing Mode="Inline" PopupEditFormWidth="500px" PopupEditFormAllowResize="True" PopupEditFormHorizontalAlign="Center"></SettingsEditing>
    <Settings EnableFilterControlPopupMenuScrolling="True" ShowFilterBar="Auto" ShowHeaderFilterButton="True" UseFixedTableLayout="True" ShowGroupFooter="VisibleAlways" ShowFilterRowMenu="True" ShowHorizontalScrollBar="True"></Settings>
</dx:ASPxGridView>

And I want that after update all data would be refreshed from datasource. How could I force reload? Or maybe somehow I could fire OnHtmlDataCellPrepared event after editing row?

I want this because I have two columns depending on one editable column, so when I edit cell from that one, cells in other two columnd must be changed accordingly (not just values but styles also). And any other way I can't access that cell style.

I'm waiting for any help about cell style changing or forcing ASPxGriwView to refresh from data source..

Answer

Rodrigo Reis picture Rodrigo Reis · Jul 25, 2012

Man,

If your grid is bound to a data source and this data source is in a Session Var, just update this data source. There's no need to bound the data source again.

Basically:

protected void Page_Load(object sender, EventArgs e) { 
    if (Session["__DataSource"] != null)
    {
        gvMyGridView.DataSource = Session["__DataSource"];
        gvMyGridView.DataBind();
    }        
}

Ok, in any event on the page, just work with the data source that is in Session Var. You can create best practices for this encapsulating the Session Var in a get/set property.