This is a migrated thread and some comments may be shown as answers.

Saving Changes to Grid without using save button in the editable grid row

1 Answer 326 Views
Grid
This is a migrated thread and some comments may be shown as answers.
adnan
Top achievements
Rank 1
adnan asked on 29 Apr 2015, 10:22 PM

I have a asp.net web page with standard Telerik Grids as well as some other Telerik controls such as text box, rich editors etc.  

Now currently in order to save data in the form users have to press save in each editable row in the grid after entering data in the row which is the standard grid behavior.  In order to save other text fields in the form, they have to press a separate Save button.  

Is it possible to have one single save button that can trigger save function in the current row in the grid that is being edited?   This single save button will additionally save all the other data in text fields as well.

Additionally users want to be able to have an auto-save feature so form is saved automatically at certain intervals or upon moving away from the page to another page on the site.   

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 04 May 2015, 11:01 AM
Hello Adnan,

For achieving the desired behavior you could manually traverse through all edit items, retrieve their values and perform manual updates in your database. If you are using the automatic CRUD operations you could use something similar to the code below:
<telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="SqlDataSource1" AllowAutomaticUpdates="true" AllowMultiRowEdit="true">
    <MasterTableView DataKeyNames="ID">
        <Columns>
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
 
<telerik:RadButton runat="server" ID="RadButton1" Text="Save" OnClick="RadButton1_Click"></telerik:RadButton>
 
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:NorthwindConnectionString %>'
    SelectCommand="SELECT * FROM [tblTest]"
    UpdateCommand="UPDATE [tblTest] SET [Col1] = @Col1, [Col2] = @Col2, [Col3] = @Col3, [ProductID] = @ProductID WHERE [ID] = @ID">        
    <UpdateParameters>
        <asp:Parameter Name="Col1" Type="String"></asp:Parameter>
        <asp:Parameter Name="Col2" Type="String"></asp:Parameter>
        <asp:Parameter Name="Col3" Type="String"></asp:Parameter>
        <asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
    </UpdateParameters>
</asp:SqlDataSource>

And the code-behind:
protected void RadButton1_Click(object sender, EventArgs e)
{  
    foreach (GridItem item in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem))
    {
        GridEditFormItem editItem = item as GridEditFormItem;
 
        if (editItem.ParentItem.Edit)
        {
            RadGrid1.MasterTableView.PerformUpdate(editItem, true);
        }
    }
}

As for the auto-save, you can use a Timer control or some other custom approach to initiate a postback and handle some server-side event to perform the same logic, as in the above example.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
adnan
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or