Javascript 尝试检测gridview的哪一行处于编辑模式,然后在选中复选框字段时调整文本框

Javascript 尝试检测gridview的哪一行处于编辑模式,然后在选中复选框字段时调整文本框,javascript,c#,jquery,asp.net,Javascript,C#,Jquery,Asp.net,我一直在研究几种不同的方法来实现这一点。当前一个正在尝试使用jquery //Find each edit link var chks = $('#ContentPlaceHolder1_GVJobList').find('a'); //For each edit link bind click with function $.each(chks, function () { $(this).on('click', function () { // trying to get the c

我一直在研究几种不同的方法来实现这一点。当前一个正在尝试使用jquery

//Find each edit link
var chks = $('#ContentPlaceHolder1_GVJobList').find('a');
//For each edit link bind click with function
$.each(chks, function () { $(this).on('click', function () {
    // trying to get the calling element
    var $self = $(this);
    // trying to get the parent(cell) then parent(row) then find the checkbox
    alert($($self).parent().parent().find('input:checkbox').val());
}) });
这是一个问题有一段时间了,所以任何帮助都将不胜感激。我愿意使用任何能够实现这一目标的方法

<asp:GridView ID="GVJobList" runat="server" AutoGenerateColumns="False" DataSourceID="SDSJobsDetails" OnRowCommand="GV_JobList_RowCommand" DataKeyNames="InvoiceID">
        <Columns>
            <asp:TemplateField HeaderText="Parts/Services">
                <ItemTemplate>
                    <asp:Button ID="B_EditJob" runat="server" CommandName="EditJob" Text="update" CommandArgument='<%# Bind("InvoiceID") %>' CausesValidation="False" UseSubmitBehavior="False" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="InvoiceID" HeaderText="InvoiceID" InsertVisible="False" ReadOnly="True" SortExpression="InvoiceID" />
            <asp:BoundField DataField="FK_CustomerID" HeaderText="FK_CustomerID" SortExpression="FK_CustomerID" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            <asp:BoundField DataField="TotalCostExGST" HeaderText="TotalCostExGST" SortExpression="TotalCostExGST" />
            <asp:BoundField DataField="TotalGST" HeaderText="TotalGST" SortExpression="TotalGST" />
            <asp:BoundField DataField="TotalCost" HeaderText="TotalCost" SortExpression="TotalCost" />
            <asp:BoundField DataField="AmountPaid" HeaderText="AmountPaid" SortExpression="AmountPaid" />
            <asp:BoundField DataField="Date_Booked" HeaderText="Date_Booked" SortExpression="Date_Booked" />
            <asp:BoundField DataField="Date_Time_Scheduled" HeaderText="Date_Time_Scheduled" SortExpression="Date_Time_Scheduled" />
            <asp:BoundField DataField="Date_Completed" HeaderText="Date_Completed" SortExpression="Date_Completed" />
            <asp:BoundField DataField="Date_Paid" HeaderText="Date_Paid" SortExpression="Date_Paid" />
            <asp:CheckBoxField DataField="completed" HeaderText="completed" SortExpression="completed" />
            <asp:CheckBoxField DataField="PaidInFull" HeaderText="PaidInFull" SortExpression="PaidInFull" />
            <asp:CheckBoxField DataField="PartPaid" HeaderText="PartPaid" SortExpression="PartPaid" />
            <asp:TemplateField HeaderText="Invoice">
                <ItemTemplate>
                    <asp:Button ID="B_CreateInvoice" runat="server" CommandName="CreateInvoice" Text="Create Invoice" CommandArgument='<%# Bind("InvoiceID") %>'  CausesValidation="False" UseSubmitBehavior="False" />
                    <asp:Button ID="B_ViewInvoice" runat="server" CommandName="ViewInvoice" Text="View Invoice" CommandArgument='<%# Bind("InvoiceID") %>'  CausesValidation="False" UseSubmitBehavior="False" />
                    <asp:Button ID="B_SendInvoice" runat="server" CommandName="SendInvoice" Text="eMail Invoice" CommandArgument='<%# Bind("InvoiceID") %>'  CausesValidation="False" UseSubmitBehavior="False" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

所以,DJ KRAZE的建议并没有足够的信息让我去做。但我发现了一个关键词组合,谷歌给出了部分答案

protected void chkChanged(object sender, EventArgs e)
{
    GridViewRow row = (GridViewRow) (sender as CheckBox).Parent.Parent;
    CheckBox chk = (sender as CheckBox);
    TextBox comp = row.Cells[11].Controls[0] as TextBox;
    TextBox totalAmt = row.Cells[7].Controls[0] as TextBox;
    TextBox paid = row.Cells[8].Controls[0] as TextBox;
    TextBox datePaid = row.Cells[12].Controls[0] as TextBox;

    if (chk.ID.Equals("CB_Completed") && chk.Checked)
    {
        comp.Text = DateTime.Now.ToString();
    }
    else if (chk.ID.Equals("CB_Completed") && !chk.Checked)
    {
        comp.Text = "";
    }

    if (chk.ID.Equals("CB_PaidInFull") && chk.Checked)
    {
       datePaid.Text = DateTime.Now.ToString();
       paid.Text = totalAmt.Text;
    }
    else if (chk.ID.Equals("CB_PaidInFull") && !chk.Checked)
    {
        datePaid.Text = "";
        paid.Text = "";
    }
}
加价呢

<asp:UpdatePanel>
    <ContentTemplate>
        <asp:GridView ID="GVJobList" runat="server" AutoGenerateColumns="False" DataSourceID="SDSJobsDetails" OnRowCommand="GV_JobList_RowCommand" DataKeyNames="InvoiceID">
            <Columns>
                <asp:TemplateField HeaderText="Parts/Services">
                    <ItemTemplate>
                        <asp:Button ID="B_EditJob" runat="server" CommandName="EditJob" Text="update" CommandArgument='<%# Bind("InvoiceID") %>' CausesValidation="False" UseSubmitBehavior="False" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="InvoiceID" HeaderText="InvoiceID" InsertVisible="False" ReadOnly="True" SortExpression="InvoiceID" />
                <asp:BoundField DataField="FK_CustomerID" HeaderText="FK_CustomerID" SortExpression="FK_CustomerID" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:BoundField DataField="TotalCostExGST" HeaderText="TotalCostExGST" SortExpression="TotalCostExGST" />
                <asp:BoundField DataField="TotalGST" HeaderText="TotalGST" SortExpression="TotalGST" />
                <asp:BoundField DataField="TotalCost" HeaderText="TotalCost" SortExpression="TotalCost" />
                <asp:BoundField DataField="AmountPaid" HeaderText="AmountPaid" SortExpression="AmountPaid" />
                <asp:BoundField DataField="Date_Booked" HeaderText="Date_Booked" SortExpression="Date_Booked" />
                <asp:BoundField DataField="Date_Time_Scheduled" HeaderText="Date_Time_Scheduled" SortExpression="Date_Time_Scheduled" />
                <asp:BoundField DataField="Date_Completed" HeaderText="Date_Completed" SortExpression="Date_Completed" />
                <asp:BoundField DataField="Date_Paid" HeaderText="Date_Paid" SortExpression="Date_Paid" />
                <asp:TemplateField HeaderText="Completed">
                    <ItemTemplate>
                        <asp:CheckBox ID="CB_Completed" Checked='<%# Bind("completed") %>' runat="server" Enabled="False" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:CheckBox ID="CB_Completed" Checked='<%# Bind("completed") %>' CommandName="comp" runat="server" Enabled="True" OnCheckedChanged="chkChanged" AutoPostBack="True" />
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="PaidInFull">
                    <ItemTemplate>
                        <asp:CheckBox ID="CB_PaidInFull" Checked='<%# Bind("PaidInFull") %>' runat="server" Enabled="False" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:CheckBox ID="CB_PaidInFull" Checked='<%# Bind("PaidInFull") %>' CommandName="full" runat="server" Enabled="True" OnCheckedChanged="chkChanged" AutoPostBack="True" />
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="PartPaid">
                    <ItemTemplate>
                        <asp:CheckBox ID="CB_PartPaid" Checked='<%# Bind("PartPaid") %>' runat="server" Enabled="False" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:CheckBox ID="CB_PartPaid" Checked='<%# Bind("PartPaid") %>' CommandName="part" runat="server" Enabled="True" OnCheckedChanged="chkChanged" AutoPostBack="True" />
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Invoice">
                    <ItemTemplate>
                        <asp:Button ID="B_CreateInvoice" runat="server" CommandName="CreateInvoice" Text="Create Invoice" CommandArgument='<%# Bind("InvoiceID") %>' CausesValidation="False" UseSubmitBehavior="False" />
                        <asp:Button ID="B_ViewInvoice" runat="server" CommandName="ViewInvoice" Text="View Invoice" CommandArgument='<%# Bind("InvoiceID") %>' CausesValidation="False" UseSubmitBehavior="False" />
                        <asp:Button ID="B_SendInvoice" runat="server" CommandName="SendInvoice" Text="eMail Invoice" CommandArgument='<%# Bind("InvoiceID") %>' CausesValidation="False" UseSubmitBehavior="False" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

这意味着对服务器有一些调用,有时可能会很慢,但它完成了任务。也许有一天我会重温整个过程,尝试让javascript或jquery来处理它


基本上,我用模板字段和复选框替换了复选框字段。这使我能够在不处于编辑模式时保持外观不变,并且asp.net为我完成了启用的工作。这允许我比较ID。然后我使用带有CheckedChange的AutoPostBack来检测帖子之间复选框的更改,这是服务器可以做到这一点的唯一方法(这是有意义的)。

如果没有HTML标记,很难回答
Peter
你在谷歌上搜索过这方面的工作示例吗。?外面有很多。。这里是一个很好的起点| |是的,我已经尝试过用谷歌搜索我能想到的一切。我最后的办法是在这里提问。我如何将committedit方法附加到gridview?