I have a grid view like this:
JavaScript
x
16
16
1
<asp:SqlDataSource ID="SqlPersistentOffenders" runat="server"></asp:SqlDataSource>
2
<asp:GridView ID="GVPersistentOffenders" runat="server" DataSourceID="SqlPersistentOffenders" AllowPaging="true" AutoGenerateColumns="false">
3
<Columns>
4
<asp:TemplateField HeaderText="PersonID" Visible="false">
5
<ItemTemplate>
6
<asp:Label ID="LabCreUser" runat="server" Text='<%# Bind("creUser")%>'></asp:Label>
7
</ItemTemplate>
8
</asp:TemplateField>
9
<asp:TemplateField>
10
<ItemTemplate>
11
<asp:Button ID="ButtonSendEmail" runat="server" CommandName="SendEmail" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" Text="Send Email" OnClientClick="GetEmailAddress()"/>
12
</ItemTemplate>
13
</asp:TemplateField>
14
</Columns>
15
</asp:GridView>
16
The JavaScript looks like this:
JavaScript
1
6
1
<script type="text/javascript">
2
function GetEmailAddress(creuser) {
3
//Do something
4
}
5
</script>
6
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.
Advertisement
Answer
You can pass the parameter to the JS function this way
JavaScript
1
2
1
OnClientClick=<%# "GetEmailAddress('" + Eval("creUser") + "')" %>
2
this will became in
JavaScript
1
2
1
OnClientClick="GetEmailAddress('yourValue')"
2