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

How to modify a column value during the OnBatchEditCommand event

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 24 Apr 2015, 11:03 PM

Hi,

I'm sure that answer already exists, but I searched through the forum and couldn't find a solution. 

I have a batch mode grid that invokes a web service, during the OnBatchEditCommand event, when saving data.  The service performs the update and returns a DataTable which identifies the results of the insert/update/delete actions.  The results include a status, error message and datetime value for every row that was processed. 

To help the user, we have a GridTemplateColumn (seen below), containing an image used to depict the results.  If the status is "Ok", we want to display a green check mark.  If the status is "Error", we want to display a red 'X'.  As you can imagine, in order for the user to correct the error, we don't want to overwrite any data that they may have entered.  As such, we don't want to reset the grids DataSource.  (Note that we do validate the data prior to calling the web service, but need to be cautious.)

<telerik:GridTemplateColumn ItemStyle-Wrap="false" DataField="STATUS" FilterControlAltText="Filter STATUS column" HeaderText="Row Status" SortExpression="STATUS" UniqueName="STATUS">
<ItemTemplate>
<asp:Image runat="server" ID="RowStatus" ImageUrl='<%#"/_layouts/15/images/projname/MUE_" + Eval("STATUS") + ".png"%>' />
</ItemTemplate>
</telerik:GridTemplateColumn>

So, after obtaining the returned DataTable, we would like to loop through the grid's rows, setting the value of the GridTemplateColumn to the value provided in the DataTable (either "Ok" or "Error").  Doing so, will allow us to display the MUE_Ok.png or MUE_Error.png image.  Obviously, we're open to other solutions that meet our user's requirements.  Note that the initial call to retrieve data, performed during the NeedDataSource event, returns a DataTable that currently includes an "Ok" value (along with all of the other data values) for each row.  As such, each row initially shows the green check mark. 

 Thanks.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 29 Apr 2015, 09:26 AM
Hi Scott,

Although that we are handling the issue in the regular support ticket that you have opened (Ticket ID: 930131), I just want to share the answer from the ticket with the community if there is someone else with similar requirement:
"I Have gone multiple times through your requirement, but I have to say that the result that you are trying to achieve is not supported scenario and will require an enormous amount of custom server-side and client-side code.

Nevertheless, following are some pointers that could help you achieve the desired result.

First, you should take into consideration the fact that all changes made on the client-side will be lost after you initiate the saving of the grid. The only option that you have to keep changes in a particular row after a postback would be to store the relevant information (the changes and some identifier) in a HiddenField control for example and manually made the same changes on the client-side (after the postback) through the BatchEditingManager .

As for the image indicator, you can store the information for the commands result from the OnBatchEditCommand event (saved or not saved) and handle the server-side OnPreRender event of the grid (which will fire after the grid rebinds and retrieves the values from the database), traverse through each GridDataItem, find the Image control that will display the status image to the user and change the ImageUrl property according to the stored information for that item.

Please note that the above will work for the updated items only, because if the inserted items are not saved in the database, after the rebinding of the grid, those items will not be present.
"


Regards,
Konstantin Dikov
Telerik
 

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

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