Jquery在Listview中不起作用

时间:2015-09-07 21:44:27

标签: jquery asp.net vb.net listview webforms

我正在使用以下代码。

我想要做的是,如果用户在txtPaidAmount中输入内容,则txtDeductAmount变为0并且如果用户在txtDeductAmount中输入内容txtPaidAmount到目前为止变为0如果我通过这些TextBox运行它可以工作但是当我尝试实现时会出现问题它在ListView lblPaidAmount和lblDeductAmount上根本不起作用。

任何人都可以帮助我解决这个问题。

Aspx Code。

<asp:ListView ID="ListView1" runat="server" >
<LayoutTemplate>
          <table class="table" style="text-align:left">
              <th>ID</th>
              <th>AcName</th>
              <th>Naration</th>
              <th>PaidAmount</th>
              <th>DeductionAmount</th>
              <th>Action</th>

                   <tr id="itemPlaceholder" runat="server"></tr>
                          </table>
                      </LayoutTemplate>

                       <ItemTemplate>
                          <tr>
                              <td>
                                  <asp:Label runat="server" ID="lblID" Text='<%#Bind("ID") %>'></asp:Label>
                              </td>
                              <td>
                                  <%--<asp:Label runat="server" ID="lblAcount" Text='<%#Eval("AcName") %>'></asp:Label>--%>
                                  <asp:TextBox ID="lblAcount" runat="server" CssClass="form-control" Text='<%#Bind("AcName") %>'></asp:TextBox>
                              </td>
                              <td>
                                  <%--<asp:Label runat="server" ID="lblNaration" Text='<%#Eval("Naration") %>'></asp:Label>--%>
                                  <asp:TextBox ID="lblNaration" runat="server" CssClass="form-control" Text='<%#Bind("Naration") %>'></asp:TextBox>
                              </td>
                              <td>
                                  <%--<asp:Label runat="server" ID="lblPaidAmount" Text='<%#Eval("PaidAmount") %>'></asp:Label>--%>
                                  <asp:TextBox ID="lblPaidAmount" runat="server" CssClass="form-control" Text='<%#Bind("PaidAmount") %>' onkeypress="return isNumberKey(event)"></asp:TextBox>
                              </td>
                              <td>
                                  <%--<asp:Label runat="server" ID="lblDeductAmount" Text='<%#Eval("DeductionAmount") %>'></asp:Label>--%>
                                  <asp:TextBox ID="lblDeductAmount" runat="server" CssClass="form-control" Text='<%#Bind("DeductionAmount") %>' onkeypress="return isNumberKey(event)"></asp:TextBox>
                              </td>

                              <td><asp:LinkButton ID="DeleteButton" cssClass="btn btn-info fa fa-trash-o" runat="server" CommandName="DeleteIt"></asp:LinkButton>


                              <%--EDIT IN THIS LINE--%>
                              <%--<asp:LinkButton ID="UpdateButton" cssClass="btn btn-info fa fa-pencil" runat="server" CommandName="UpdateIt"></asp:LinkButton>--%></td>
                              <%--EDIT IN THIS LINE--%>


                              <td>
                              </td>

                              <%--<asp:Panel ID="Panel2" runat="server" Visible="False">
                                  <tr>
                                            <td>
                                                <asp:Label ID="Label12" runat="server" Text="Credit Acount"></asp:Label>
                                                <asp:TextBox ID="txtAcName" runat="server" CssClass="form-control" Text='<%#Bind("AcName") %>'></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="Label13" runat="server" Text="Naration"></asp:Label>
                                                <asp:TextBox ID="txtNaration" runat="server" CssClass="form-control" Text='<%#Bind("Naration") %>'></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="Label14" runat="server" Text="Paid Amount"></asp:Label>
                                                <asp:TextBox ID="txtPaidAmount" runat="server" CssClass="form-control" Text='<%#Bind("PaidAmount") %>'></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="Label15" runat="server" Text="Deduction Amount"></asp:Label>
                                                <asp:TextBox ID="txtDeductAmount" runat="server" CssClass="form-control" Text='<%#Bind("DeductionAmount") %>'></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:LinkButton ID="btnUpdateRecord" cssClass="btn btn-info fa fa-check" runat="server" CommandName="UpdateRecord"></asp:LinkButton>
                                                <asp:LinkButton ID="btnCancelUpdate" cssClass="btn btn-info fa fa-close" runat="server" CommandName="CancelUpdate"></asp:LinkButton>
                                            </td>
                                        </tr>                                        
                                    </asp:Panel>--%>
                          </tr>
                      </ItemTemplate>

                      <%--<InsertItemTemplate>--%>
                          <%--<tr id="Tr1" runat="server">
                            <td>
                            </td>
                            <td>
                                <asp:TextBox ID="txtAcName" runat="server" CssClass="form-control" Text='<%#Eval("AcName") %>'
                                    Width="100px" AutoPostBack="True">Naration</asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="txtNaration" runat="server" CssClass="form-control" Text='<%#Eval("Naration") %>'
                                    Width="100px">Naration</asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="txtPaidAmount" runat="server" CssClass="form-control" onkeydown="change()" Text='<%#Eval("PaidAmount") %>'
                                    Width="100px">PaidAmount</asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="txtDeductAmount" runat="server" CssClass="form-control" onkeydown="change1()" Text='<%#Eval("DeductionAmount") %>'
                                    Width="100px">DeductionAmount</asp:TextBox>
                            </td>
                            <td>
                                <asp:LinkButton ID="InsertButton" runat="server" CommandName="Add" CssClass="btn btn-info">Insert</asp:LinkButton>
                            </td>
                        </tr>--%>

                      <%--</InsertItemTemplate>--%>

                  </asp:ListView>

使用此Markup,我将Row添加到数据库,然后在Listview中显示。

<table id="EntryTable">
        <tr id="Tr1" runat="server">
               <td>
               </td>
               <td>
               </td>
               <td>
               </td>
               <td>
               </td>
               <td>
                <asp:TextBox ID="txtAcName" runat="server" CssClass="form-control" Text=''
                                    Width="100px" PlaceHolder="Acount Name" onkeypress="return isQuotation(event)"></asp:TextBox>
               </td>
                <td>
                 <asp:TextBox ID="txtNaration" runat="server" CssClass="form-control" Text=''
                                    Width="100px" PlaceHolder="Naration" onkeypress="return isQuotation(event)"></asp:TextBox>
                </td>
                <td>
                 <asp:TextBox ID="txtPaidAmount" runat="server" CssClass="form-control" onkeydown="change()" Text=''
                                    Width="100px" PlaceHolder="Paid Amount" onkeypress="return isNumberKey(event)"></asp:TextBox>
                            </td>
                            <td>
                <asp:TextBox ID="txtDeductAmount" runat="server" CssClass="form-control" onkeydown="change1()" Text=''
                                    Width="100px" PlaceHolder="DeductionAmount" onkeypress="return isNumberKey(event)"></asp:TextBox>
                </td>
                <td>
                <asp:LinkButton ID="InsertButton" runat="server" CssClass="btn btn-info">Insert</asp:LinkButton>
                            </td>
                        </tr>

          </table>

用于将下一个TextBox设置为0的JS。

function change() {
            var t1Val = document.getElementById("<%=txtPaidAmount.ClientID %>");
            document.getElementById("<%=txtDeductAmount.ClientID %>").value = 0;
        };

        function change1() {
            var t2Val = (document.getElementById("txtDeductAmount")).value;
            (document.getElementById("txtPaidAmount")).value = 0;
        };

0 个答案:

没有答案