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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

127713 Dec 4,2016 10:52 PM UTC Dec 14,2016 11:07 AM UTC ASP.NET Web Forms 8
loading
Tags: Grid
Pratheep
Asked On December 4, 2016 10:52 PM UTC

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

Venkatesh Ayothi Raman [Syncfusion]
Replied On 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.  


Pratheep
Replied On December 6, 2016 03:42 AM UTC

Hi Venkatesh Ayothiraman

Thank you for your support.Working fine.

Thanks
Pratheep

Venkatesh Ayothi Raman [Syncfusion]
Replied On 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. 


Pratheep
Replied On 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

Mohammed Farook J [Syncfusion]
Replied On 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 


Pratheep
Replied On 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

Pratheep
Replied On 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

Mohammed Farook J [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;