Pass more than one Values(databinder.eval) to Javascript Functiont

May 3, 2010

In my previous one Post i written about how to pass a databinder.eval value to JavaScript function. It is showing that how can we pass a single value to JavaScript function but in some case we required to pass more than one values to JavaScript function. To do that we need to use String.Format.

Here is the Small Example for the same.

I have a Javascript Function by name ‘showValues’ with three Parameters like ID of type int, FirstName of type string and LastName of type string. i want to call this function on OnClientClick event of the LinkButton Control.

Here is my Javascript Function’s Definition:
function showValues(ID, FirstName, LastName)
{
   alert(ID + ‘,’ + FirstName+ ‘,’ + LastName);
   return false;
}

now to call this function i have added ‘OnClientClick’ event of the LinkButton like this in the Grid TemplateField:

<asp:TemplateField HeaderText=”LastName”>
  <ItemTemplate>
   <asp:LinkButton ID=”lnkClick”  OnClientClick='<%#String.Format(“return showValues({0},
&#39;{1}&#39;,&#39;{2}&#39;)”, Eval(“ID”),  Eval(“FirstName”),  Eval(“LastName”)) %>’  runat=”server”> <%# Eval(“LastName”) %>     </asp:LinkButton>
  </ItemTemplate>
</asp:TemplateField>

Click Here  to see how your OnClientClick event should be written.

Thats it!!!! 🙂
Enjoy Coddig……..