BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
<script type="text/javascript">
$(function () {
$(".Details").ejButton({
click: function (e) {
var obj = $('#<%= ProductGrid.ClientID %>').data("ejGrid");
var args = { currentTarget: this.element[0].name, selectedRecord: obj.getSelectedRecords(), selectedIndex: obj.model.selectedRowIndex };
$.ajax({
type: "POST",
url: "workorder.aspx/ButtonQueries",
datatype: "json",
contentType: "application/json",
data: JSON.stringify(args),
success: function (response) {
},
});
}
});
});
</script>
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<Materials> ButtonQueries(string currentTarget, List<object> selectedRecord, int selectedIndex)
{
List<Materials> materials = new List<Materials>();
Dictionary<object, string> dictionary = new Dictionary<object, string>();
dictionary = selectedRecord.ToDictionary(x => x, x => string.Format("Val: {0}", x));
foreach (IDictionary<string, object> row in selectedRecord)
{
foreach (KeyValuePair<string, object> entry in row)
{
if (entry.Key == "10001")
{
materials.Add(new Materials(20001, "AAAAA"));
materials.Add(new Materials(20002, "BBBB"));
}
if (entry.Key == "10002")
{
materials.Add(new Materials(20003, "CCCC"));
materials.Add(new Materials(20004, "DDDD"));
}
}
}
return materials;
}
@workorder.aspx page
$(".Details").ejButton({
click: function (e) {
var obj = $('#<%= ProductGrid.ClientID %>').data("ejGrid");
var args = { currentTarget: this.element[0].name, selectedRecord: obj.getSelectedRecords(), selectedIndex: obj.model.selectedRowIndex };
$.ajax({
type: "POST",
url: "workorder.aspx/ButtonQueries",
datatype: "json",
contentType: "application/json",
data: JSON.stringify(args),
success: function (response) {
var materialGridObject = $("#MaterialGrid").ejGrid('instance'); //create a grid instance
materialGridObject.dataSource(response.d); //bind the datasource to material in suceess function Grid
},
});
}
});
@server side
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<Materials> ButtonQueries(string currentTarget, List<object> selectedRecord, int selectedIndex)
{
. . .
foreach (IDictionary<string, object> row in selectedRecord)
{
foreach (KeyValuePair<string, object> entry in row)
{
if (entry.Value.ToString() == "10001")
{
materials.Add(new Materials(20001, "AAAAA"));
materials.Add(new Materials(20002, "BBBB"));
}
if (entry.Value.ToString() == "10002")
{
materials.Add(new Materials(20003, "CCCC"));
materials.Add(new Materials(20004, "DDDD"));
}
}
}
return materials;
}
|
function saveClick() {
var grid = $('#<%= MaterialGrid.ClientID %>').ejGrid("instance");
var object = JSON.stringify(grid.model.dataSource);
alert(grid);
alert(object);
$.ajax({
type: "POST",
url: "Workorder.aspx/materialsave",
datatype: "json",
contentType: "application/json",
data: JSON.stringify({ "grid": object }),
success: function () {
},
});
}
[WebMethod]
public static object materialsave(string grid )
{
// __type":"WebApplication1.workproduct+Materials
IList<Materials> gridData = new JavaScriptSerializer()
.Deserialize<IList<Materials>>(grid);
return new { result = grid };
}
Thanks
IList<Materials> gridData = new JavaScriptSerializer()
.Deserialize<IList<Materials>>(grid);
Thanks
Thanks