Gridview中不起作用

Gridview中不起作用

本文介绍了jQuery类选择器在ASP.Net Gridview中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码,我试图在下拉菜单"ddlAction"的更改事件上编写一些验证代码.

Using the below code I am trying to write some validation code on change event of dropdown "ddlAction".

我尝试了几种方法,例如

I have tried few ways e.g.

  1. $(".ddlAction").change(function () {

$("#grdApproval").find("[id^='ddlAction']").change(function () {

$("input[id*=ddlAction]").change(function ()

$("input[value*=ddlAction]").change(function () {

  1. ->仅在我位于gridview的第一页时有效.

C#代码:

<asp:TemplateField HeaderText="ACTION" ItemStyle-Width="10%">
    <ItemTemplate>
        <asp:DropDownList ID="ddlAction" CssClass="ddlAction" runat="server" BorderStyle="Solid" Width="150px" SkinID="GridEdit" ValidationGroup="Compensation" Enabled="true"/>
    </ItemTemplate>
</asp:TemplateField>

JQuery:

$(function () {
    $(".ddlAction").change(function () {
    //$("#grdApproval").find("[id*='ddlAction']").change(function () {
    //$("input[id*=ddlAction]").change(function () {
    //$("input[value*=ddlAction]").change(function () {
        //do something;
    });
});

页面源:

<select name="ctl00$MainContent$grdApproval$ctl03$ddlAction" id="MainContent_grdApproval_ddlAction_1" class="ddlAction" style="color:Black;background-color:#FFFF99;border-style:Solid;font-family:Verdana;font-size:9pt;width:150px;">
<option value="97" title="-----------Select-----------">-----------Select-----------</option>
<option value="FS" title="Finalize-Submit">Finalize-Submit</option>
<option value="NMR" title="Needs More Research">Needs More Research</option>

推荐答案

以下代码有效,并且在异步回发后通过重新附加事件修复了问题

Below code worked and issue fixed by re-attaching event after async-postback

function pageLoad(sender, args) {
$(document).ready(function () {
    $(".ddlAction").change(function () {
        var HFStatusChangedId = this.id.replace("ddlAction", "HFStatusChanged");
        if (this.selectedIndex !== "97") {
            document.getElementById(HFStatusChangedId).value = "Y";
        }
    });
});

}

这篇关于jQuery类选择器在ASP.Net Gridview中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:23