- Home
- Forum
- ASP.NET Web Forms
- Select Productcode from ProductGrid - find Material details according to the Prodcut code and fill MaterialGrid
Select Productcode from ProductGrid - find Material details according to the Prodcut code and fill MaterialGrid
it's possible, if select product code (grid button click) Json find material details and fill MaterialGrid according to the product code
<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;
}
Thanks
Pratheep
Attachment: WebApplication1_778009f0.rar
|
@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;
}
|
Thank you for your support.Working fine.
Thanks
Pratheep
When Saving MaterialGrid
Json get data in code behind - that data contain word __type":"WebApplication1.workproduct+Materials
dont know where this word coming from
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 };
}
ThanksPratheep
Attachment: WebApplication1_32108d33.rar
Thank you for your replay
Is there any possibility stop Json get data. because that showing error in web page
__type":"WebApplication1.workproduct+Materials
IList<Materials> gridData = new JavaScriptSerializer()
.Deserialize<IList<Materials>>(grid);
Thanks
Pratheep
Thank you for your replay
Is there any possibility remove that word ( __type":"WebApplication1.workproduct+Materials) Json get data. because that showing error in web page
Thanks
Pratheep
- 8 Replies
- 3 Participants
-
PR Pratheep
- Dec 4, 2016 10:52 PM UTC
- Dec 14, 2016 11:07 AM UTC