We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Select Productcode from ProductGrid - find Material details according to the Prodcut code and fill MaterialGrid

Hi

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

8 Replies

VA Venkatesh Ayothi Raman Syncfusion Team December 5, 2016 03:30 PM UTC

Hi Pradeep, 
Thanks for contacting Syncfusion support. 
We went through your sample and found that you wrongly checked the condition in server side like “entry.Key == ‘1001’ ” instead of “entry.Value.ToString() == ‘1001’ ”. Please refer to the code example and we have also modified your sample.  
Code example
@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; 
        } 
 


Regards, 
Venkatesh Ayothiraman.  



PR Pratheep December 6, 2016 03:42 AM UTC

Hi Venkatesh Ayothiraman

Thank you for your support.Working fine.

Thanks
Pratheep


VA Venkatesh Ayothi Raman Syncfusion Team December 8, 2016 04:20 AM UTC

Hi Pradeep, 

Thanks for the update. 
We are happy to hear that your requirement is achieved. 

Thanks, 
Venkatesh Ayothiraman. 



PR Pratheep December 9, 2016 01:39 PM UTC

Hi

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 };

        }

Thanks
Pratheep


Attachment: WebApplication1_32108d33.rar


MF Mohammed Farook J Syncfusion Team December 13, 2016 10:44 AM UTC

Hi Pratheep 
 
We have validated your provided sample and code example please find the response. 
The “ materialSave “ method can access from the webApplication1 namespace and wrokProduct class.  
 
Please find the screen shot for your reference. 
 
 
 
 
Regards, 
J.Mohammed Farook 



PR Pratheep December 13, 2016 02:41 PM UTC

Hi

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


PR Pratheep December 13, 2016 02:43 PM UTC

Hi

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


MF Mohammed Farook J Syncfusion Team December 14, 2016 11:07 AM UTC

Hi Pratheep, 
 
We have validated your requirement and this general issue while get JSON  from the meta data format . please find the online solution for this issue. 
 
  
 
Regards, 
J.Mohammed Farook 


Loader.
Live Chat Icon For mobile
Up arrow icon