Hi, I'm having 2 radgrids (rgRole and rgRecei) in batch edit mode on same page.I'm using 1 html button to call OnBatchEditCommand from outside to save it. But my problem is that it can call only 1 of second radgrid and dismiss the first one.
function SaveRg() {
$find('rgRole').get_batchEditingManager().saveChanges('rgRole_ctl00')
$find('rgRecei').get_batchEditingManager().saveChanges('rgRecei_ctl00');
return false;
}
So how do i get NewValues of radgrid in code behind in another function like
protected void getRadGridNewValues(){
// get newValue of rgRole here
// get newValue of rgRecei here
}
Any help appreciated,
Thanks,
Hiep
1 Answer, 1 is accepted
In order to save the data for multiple RadGrid controls with a single click you can use the saveTableChanges() method. Check out the following code snippets that illustrate the approach.
Markup:
<
asp:Button
Text
=
"Save All"
runat
=
"server"
ID
=
"Button1"
OnClientClick
=
"clientClick(); return false;"
/>
JavaScript
function
clientClick() {
var
grid1 = $find(
"<%= RadGrid1.ClientID %>"
);
var
masterTable1 = grid1.get_masterTableView();
var
grid2 = $find(
"<%= RadGrid2.ClientID %>"
);
var
masterTable2 = grid2.get_masterTableView();
var
batchEditManager = grid2.get_batchEditingManager();
var
tables = [];
tables.push(masterTable1);
tables.push(masterTable2);
batchEditManager.saveTableChanges(tables);
}
Regards,
Viktor Tachev
Telerik
Hi Viktor
I saw your point but what i need is get value in behind code, because i have to handle and validate it. Can you give me a demo use OnClick event.
Thanks,
Hiep
Hi Viktor
That worked perfectly, thanks so much!
Hiep
I am glad to hear that the suggestion was helpful to you. In case you have further queries do not hesitate to contact us again.
Regards,
Viktor Tachev
Telerik
Hi, Viktor, I followed the instructions to save both grids but in the code behind, my Command object is not correct. Instead of "Insert" commandtype, I get Update and old and new values are empty. Please help!
Command object in debugger:
e.Commands[0]
{Telerik.Web.UI.GridBatchEditingCommand}
Arguments: Count = 4
Canceled: false
Item: null
NewValues: null
OldValues: Count = 0
OwnerTableView: {Telerik.Web.UI.GridTableView}
Type: Update
C# code:
protected
void
gridBenefitVerification_BatchEditCommand(
object
sender, GridBatchEditingEventArgs e)
{
// Benefit Verification data
for
(
int
i = 0; i < e.Commands.Count; i++)
{
var currentCommand = e.Commands[i];
if
(currentCommand.Type == GridBatchEditingCommandType.Insert)
{
EscalationCaseBv escalationBv = EscalationCaseBv.NewEscalationCaseBv();
escalationBv.EscalationCaseId = Convert.ToInt64(ViewState[
"escalationCaseId"
]);
escalationBv.DateVerified = Convert.ToDateTime(currentCommand.NewValues[
"DateVerified"
]);
escalationBv.CreateUser = Session[
"username"
].ToString();
escalationBv.Update();
}
}
ViewState[
"BVs"
] = EscalationCaseBvCollection.GetEscalationCaseBvCollection(Convert.ToInt64(ViewState[
"escalationCaseId"
]));
}
Javascript Code:
function
saveChanges() {
if
(Page_IsValid) {
<%--
var
grid = $find(
"<%= gridPrescriptions.ClientID %>"
);
if
(grid.get_masterTableView().get_dataItems().length > 0) {
grid.get_batchEditingManager().saveChanges(grid.get_masterTableView());
}
else
{
var
label = document.getElementById(
"<%= lblMessage.ClientID%>"
);
label.innerText =
"Please add at least one prescription."
;
label.style.color =
"red"
;
label.style.display =
""
;
document.body.scrollTop = document.documentElement.scrollTop = 0;
}--%>
var
gridRx = $find(
"<%= gridPrescriptions.ClientID %>"
);
var
masterTableRx = gridRx.get_masterTableView();
if
(masterTableRx.get_dataItems().length > 0) {
var
gridBv = $find(
"<%= gridBenefitVerification.ClientID %>"
);
var
masterTableBv = gridBv.get_masterTableView();
var
batchEditManager = gridBv.get_batchEditingManager();
var
tables = [];
var
changes1 = gridBv.get_batchEditingManager()._changes;
var
changes2 = gridRx.get_batchEditingManager()._changes;
tables.push(masterTableRx);
tables.push(masterTableBv);
batchEditManager.saveTableChanges(tables);
}
else
{
var
label = document.getElementById(
"<%= lblMessage.ClientID%>"
);
label.innerText =
"Please add at least one prescription."
;
label.style.color =
"red"
;
label.style.display =
""
;
document.body.scrollTop = document.documentElement.scrollTop = 0;
}
}
}
Me too,
plz share solution for me.
Thanks !
Hi Anh,
Did you try the solution provided by Viktor on 12th of June? - https://www.telerik.com/forums/how-do-i-save-2-radgrids-by-only-1-outside-button#bJYgYZ3sh0iEDanQql6cwQ
If it is not working for your scenario, please, send me a sample where I can examine the setup that you have and see why the suggested approach is not behaving as expected.
Regards,
Vessy
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello,
I have exactly the same problem. When I try to insert the new record, I get the same:
Command object in debugger:
e.Commands[0]
{Telerik.Web.UI.GridBatchEditingCommand}
Arguments: Count = 4
Canceled: false
Item: null
NewValues: null
OldValues: Count = 0
OwnerTableView: {Telerik.Web.UI.GridTableView}
Type: Update
I have the same implementation on the aspx page as Victore, but I don't see backend implementation nowhere in this post.
Type is Update, even though it should be Insert, and new values are not there (except in Arguments, but it is not accessible).
Thanks.
Mira
Hi Mira,
In your case, the reason the NewValues was null is checking for the changes in RadGrid using the following code, and you discovered that on your own.
function hasChanges(grid) {
batchManager = grid.get_batchEditingManager();
return (batchManager._extractChangesString(grid.get_masterTableView()) === "") ? false : true;
}
The issue appears to be related to the hasChanges() method clears flags for deleting records Bug report.
Nevertheless, I was able to come up with a workaround that might work. I will share it here as well:
Use this code to check for changes instead of the one from the Bug report article.
function hasChanges(grid) {
var result = false;
grid.get_batchEditingManager()._loopChanges(grid.get_masterTableView(), function () {
result = true;
}, false);
return result;
}
Note: this workaround has not been tested in all scenarios, therefore, it is not guaranteed to work for all cases.