w0051977 w0051977 - 5 months ago 128x
Vb.net Question

Pass GridView column value to Javascript function - OnClientClick

I have a grid view like this:

<asp:SqlDataSource ID="SqlPersistentOffenders" runat="server"></asp:SqlDataSource>
<asp:GridView ID="GVPersistentOffenders" runat="server" DataSourceID="SqlPersistentOffenders" AllowPaging="true" AutoGenerateColumns="false">
<asp:TemplateField HeaderText="PersonID" Visible="false">
<asp:Label ID="LabCreUser" runat="server" Text='<%# Bind("creUser")%>'></asp:Label>
<asp:Button ID="ButtonSendEmail" runat="server" CommandName="SendEmail" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" Text="Send Email" OnClientClick="GetEmailAddress()"/>

The JavaScript looks like this:

<script type="text/javascript">
function GetEmailAddress(creuser) {
//Do something

How can I pass the value in LabCreUser for the row selected to the Javasript function?

I have looked here: Passing variables to javascript in onclientclick and also a few other questions. Nothing I have tried has worked.


You can pass the parameter to the JS function this way

OnClientClick=<%# "GetEmailAddress('" + Eval("creUser") + "')" %>

this will became in