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

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……..

Advertisements

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

  1. Nishant Dave says:

    Excellent!!!!!!!!!!!

  2. Karthick Chokkalingam says:

    Superb!!!!!

  3. Suganya says:

    GREAT!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: