gpt4 book ai didi

javascript - 无法获取 asp :Checkbox ID for jquery in .net c#

转载 作者:行者123 更新时间:2023-11-30 18:42:20 27 4
gpt4 key购买 nike

有人知道这是怎么回事吗?我的 aspx 文件中有以下代码:

<tr>   
<th class="graytext r">Add Reps to Team:</th>
<td>
<asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID" DataSourceID="dsEmployees" EnableViewState="false" GridLines="None" CssClass="clGridDirectory">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox runat="server" ID="employee_name" Text='<%# Eval("fullname") %>'/>
<asp:HiddenField runat="server" ID="employeeidToRep" Value='<%# Eval("employeeid") %>'/>
<asp:TextBox runat="server" ID="repID" Text='<%# Eval("rep_id") %>' CssClass="cl_required_for_sale" data-messages="{required:'required'}" />
<asp:RequiredFieldValidator ID="reqvrepID" runat="server" ControlToValidate="repID" Display="Dynamic" EnableClientScript="true" ErrorMessage="required" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsEmployees" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="app_staff_without_team_select" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</td>
</tr>

我尝试使用以下代码在用户单击复选框后收到提醒:

<script type="text/javascript">
$('#<%= employee_name.ClientID %>').change(function () {
alert('bingo')
});
</script>

但是当我尝试运行该页面时,错误消息以某种方式显示:

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'employee_name' does not exist in the current context

Source Error:

Line 121: <script type="text/javascript">
Line 122: $('#<%= employee_name.ClientID %>').click(function () {

有人知道我的 jQuery 代码出了什么问题吗?我怎么只能获取 jQuery 的复选框 ID?

最佳答案

你也可以使用

<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox onclick="javascript:alert('clicked')" runat="server" ID="employee_name" Text='<%# Eval("fullname") %>' />
</ItemTemplate>
</asp:TemplateField>

CheckBox 的 onclick 事件上添加 JS 函数

关于javascript - 无法获取 asp :Checkbox ID for jquery in .net c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6502249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com