Jquery Grid Checkbox值

时间:2012-10-11 07:32:43

标签: jquery asp.net

大家好我有一个带复选框列的网格并被禁用。以及带图像按钮的列,当我单击图像按钮时,应该获取行中复选框的相应检查值。

这是我的网格,

                <asp:TemplateField HeaderText="Status" ItemStyle-Width="10%">
                    <ItemTemplate>
                        <asp:CheckBox ID="chkStatus" runat="server" Checked='<%# Eval("Deleted") %>'  Text="InActive" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Options" ItemStyle-Width="10%">
                    <ItemTemplate>
                        <asp:ImageButton ID="ImageButton1" CommandName="Edit" ImageUrl="images/Edit.gif"
                            OnClick='<%# Eval("ID", "ShowEditBox({0});return false;") %>' runat="server"
                            ToolTip="Edit" />
                        <asp:ImageButton ID="imgDelete" CommandName="Delete" ImageUrl="images/Delete.gif"
                            OnClientClick='<%# Eval("ID", "DeleteRecord({0});return false;") %>' runat="server"
                            ToolTip="Active/InActive" />
                    </ItemTemplate>
                </asp:TemplateField>

下面是Jquery方法,

function ShowEditBox(id) 
{
    $("#divEditBox").slideDown("medium");
    var pid = 'PName' + id;
    var colIndex = 0;

    var $tr = $("#" + pid).parent().parent();
    $tr.find('td').each(function() {
        if (colIndex == 1) {
            $("#txtGroupName").val($(this).text());
        }
        if (colIndex == 2) {

            if (this.checked) { alert("true"); } else { alert("false"); } 

//            
//            alert($('#' + '<%= chkStatus.ClientID %>').is(':checked'));
//            alert($(this).text());
        }
        colIndex++;
    })
    $("#editId").val(id);
    $("#lblPopTitle").text("Modify Group");
}

当我单击编辑按钮时,showsit()jquery方法总是将复选框值返回为false。

任何人请帮助我.... 感谢

2 个答案:

答案 0 :(得分:0)

this中的this.checked关键字是td函数中的.each。 首先必须找到复选框。做类似的事情:

var checked = $(this).find(input:checkbox).is(':checked');

答案 1 :(得分:0)

嗨你的TD循环应该是这样的,我没有检查它但它应该是这样的

$tr.find('td').each(function () {
        if ($(this).index == 1) {
            $("#txtGroupName").val($(this).text());
        }
        if ($(this).index == 2) {
            if($(this).find("input:checkbox").is(':checked'))
            {
                alert("true")
            }
        }
    })