'How to pass Eval arguments as parameters in javascript function from a button in GridView

'Im pretty new in asp.net webforms and i came across this problem where I want to pass eval arguments as parameters in javascript and it somehow does not provoke the javascript function'

C#

 <asp:GridView ID="CustomerOrderGrid" CssClass="Gridview" runat="server"
    Width="100%">
         <Columns>
           <asp:TemplateField ItemStyle-BackColor="#bee3f1" ItemStyle-CssClass="text-left CustomerGrid 
           OrderGridRow" ItemStyle-Width="150px"  
                HeaderText="ORDER DATA">
           <ItemTemplate >
              <p>
    <button class="btn btn-primary" 
           onclick='<%# "ShowOrderDetails(" +Eval("OrderCode") + "," +Eval("CustomerName") + "," +Eval("CustomerMobileNumber") + " );" %>' >View Details
    </button>
              </p>
              </ItemTemplate>
              </asp:TemplateField>
              </Columns>
    </asp:GridView>

Javascript

function ShowOrderDetails(OrderCode, CustomerName, CustomerMobile)
{
    alert(OrderCode);
}
   


Solution 1:[1]

try something like below should work

 onclick='<%# String.Format("ShowOrderDetails(\"{0}\",\"{1}\",\"{2}\")",Eval("OrderCode"),Eval("CustomerName"),Eval("CustomerMobileNumber"))%>'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 शेखर