1

'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);
}
   
5
  • Does this answer your question? Passing Eval from ASPX to Javascript function as Parameter Commented Apr 16, 2022 at 8:06
  • I saw this and also followed it but sadly didnt work Commented Apr 16, 2022 at 8:13
  • what javascript error you are getting Commented Apr 16, 2022 at 8:29
  • you will require to pass the function parameters in double quotes. try to use String.Format in the example. Commented Apr 16, 2022 at 8:33
  • Yes Brother your second solution worked the format of the string that I used was not correct Thank you Commented Apr 16, 2022 at 9:54

1 Answer 1

0

try something like below should work

 onclick='<%# String.Format("ShowOrderDetails(\"{0}\",\"{1}\",\"{2}\")",Eval("OrderCode"),Eval("CustomerName"),Eval("CustomerMobileNumber"))%>'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.