Jquery在Listview中不起作用 [英] Jquery doesnt work in Listview where it should work

查看:61
本文介绍了Jquery在Listview中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码。



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



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



Aspx Code。



I am using the Following code.

What I'm trying to do is if User enters something in txtPaidAmount the txtDeductAmount becomes 0 and if User enters something in txtDeductAmount txtPaidAmount becomes 0 so far If I run it through these TextBoxes it works but Problem arise when I Try to implement it on ListView lblPaidAmount and lblDeductAmount it doesn't work at all.

Can anyone Help me out with this.

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>





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





With this Markup I am adding Row to the Database which is then shown in the 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>





The JS I am using to set the next TextBox to 0.





The JS I am using to set the next TextBox to 0.

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;
        };

 function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
                return false;

            return true;
        }

        function isQuotation(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode == 39)
                return false;

            return true;
        }

推荐答案

If your controls are in a ListView and the listview is bound to five items, which of those 5 txtPaidAmount controls do you think you’re referring to in this code?



var t1Val = document.getElementById(\"<%=txtPaidAmount.ClientID %>\");



Try something like this;



If your controls are in a ListView and the listview is bound to five items, which of those 5 txtPaidAmount controls do you think you're referring to in this code?

var t1Val = document.getElementById("<%=txtPaidAmount.ClientID %>");

Try something like this;

<asp:ListView runat="server" ID="MyListView" OnItemDataBound="MyListView_ItemDataBound">
    <ItemTemplate>
        Paid: <asp:TextBox ID="txtPaidAmount" runat="server" />
        Deduct: <asp:TextBox ID="txtDeductAmount" runat="server" />
    </ItemTemplate>
</asp:ListView>







<script type="text/javascript">
    function change(paid, deduct) {
        var t1Val = document.getElementById(paid);
        document.getElementById(deduct).value = 0;
    };
</script>





code-behind;





code-behind;

protected void MyListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    if (e.Item.ItemType == ListViewItemType.DataItem)
    {
        TextBox txtPaidAmount = (TextBox)e.Item.FindControl("txtPaidAmount");
        TextBox txtDeductAmount = (TextBox)e.Item.FindControl("txtDeductAmount");

        txtPaidAmount.Attributes.Add("onkeydown", string.Format("change('{0}','{1}')", txtPaidAmount.ClientID, txtDeductAmount.ClientID));
    }
}


这篇关于Jquery在Listview中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆