Navi's

Necessity, the mother of invention

  • Twitts

  • RSS My Reader

    • An error has occurred; the feed is probably down. Try again later.
  • Top Clicks

    • None
  • Visitor Map

    Locations of Site Visitors
  • Flag Counter

    free counters

Pass Eval value in javascript function from GridView

Posted by Navi's on February 2, 2011


In Gridview, some times we need to pass (Eval(“Column”)) value in javascript function on LinkButton or HyperLink. But you can not directly pass eval value in javascript function like this

 
<asp:LinkButton id='lnk' runat='server' OnClientClick='javascript:somefun('<%# Eval("columnname") %>')' />

This will give error. To resolve this problem we need to use bellow syntax..

 
<asp:LinkButton id='lnk' runat='server' OnClientClick='<%#Eval("columnname","javascript:somefun({0});")%>' />

This is the best way to pass eval value in javascript function from GridView’s LinkButton / HyperLink.

enjoy 🙂

Reference: http://bit.ly/hSP1LI

7 Responses to “Pass Eval value in javascript function from GridView”

  1. guru2friends said

    Thanks Navi, This is what I looked for long time. It is working fine.
    Guru

  2. shwetamber said

    its not working for me. The Final html will be

    Now javascript function will gives error – Abheri is not defined.

    I don’t get the alert message. below is javascript function.

    function test(pnl)
    {
    alert(‘test’);
    }

  3. malek said

    if we have 2 eval value; how can we pass them?

  4. kinjal shah said

    Thank’s Navi

  5. Anna-Pia said

    Thank you! After going through tons of suggestions this finally helped me out.

  6. Rajesh said

    Nice answer searched for passing column value to javascript function for many hours……….

  7. vijeesh said

    Thanks brother

Leave a reply to Anna-Pia Cancel reply