Bomberlt
Bomberlt

Reputation: 259

How to refresh ASPxGridView from database after edit

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..

Upvotes: 2

Views: 10354

Answers (2)

Rodrigo Reis
Rodrigo Reis

Reputation: 1117

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.

Upvotes: 2

platon
platon

Reputation: 5340

Based on your aspx markup I see that the ASPxGridView's DataSource is set at runtime. If so, the easiest solution to this problem is to fill the DataTable with the updated data from the DB server, set the control's DataSource property and finally call the ASPxGridView's DataBind method:

ASPxGridView1.DataSource = dataTable;
ASPxGridView1.DataBind();

Upvotes: 0

Related Questions