3

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">
    <Columns>
        <asp:TemplateField HeaderText="PersonID" Visible="false">
            <ItemTemplate>
                 <asp:Label ID="LabCreUser" runat="server" Text='<%# Bind("creUser")%>'></asp:Label>                       
            </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="ButtonSendEmail" runat="server" CommandName="SendEmail" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" Text="Send Email" OnClientClick="GetEmailAddress()"/>                     
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

The JavaScript looks like this:

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

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.

0

2 Answers 2

14

You can pass the parameter to the JS function this way

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

this will became in

OnClientClick="GetEmailAddress('yourValue')"
Sign up to request clarification or add additional context in comments.

Comments

1

You can replace the <asp:button> with an HTML button, and use onclick to call your JavaScript function, and if you need a server side function add runat="server"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.