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
guru2friends said
Thanks Navi, This is what I looked for long time. It is working fine.
Guru
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’);
}
malek said
if we have 2 eval value; how can we pass them?
kinjal shah said
Thank’s Navi
Anna-Pia said
Thank you! After going through tons of suggestions this finally helped me out.
Rajesh said
Nice answer searched for passing column value to javascript function for many hours……….
vijeesh said
Thanks brother