[英]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">
<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: JavaScript 看起来像这样:
<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?如何将 LabCreUser 中所选行的值传递给 Javasript 函数?
I have looked here: Passing variables to javascript in onclientclick and also a few other questions.我看过这里: Passing variables to javascript in onclientclick以及其他一些问题。 Nothing I have tried has worked.
我试过的都没有用。
You can pass the parameter to the JS function this way您可以通过这种方式将参数传递给JS函数
OnClientClick=<%# "GetEmailAddress('" + Eval("creUser") + "')" %>
this will became in这将成为
OnClientClick="GetEmailAddress('yourValue')"
您可以将<asp:button>
替换为 HTML 按钮,并使用onclick
调用您的 JavaScript 函数,如果您需要服务器端函数,请添加runat="server"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.